SrgbColor

Represents a color in the sRGB color space.

This is the standard color space for web and digital displays. Components are
stored as red, green, and blue values in the range [0, 1].

Methods

public function analogous(int $count): array
Parameters
NameTypeDefault
$count int 2
public function blend(ColorInterface|string $backdrop, string $mode): static
Parameters
NameTypeDefault
$backdrop ColorInterface|string -
$mode string "normal"
public function complementary(): static
public function cool(float $amount): static
Parameters
NameTypeDefault
$amount float -
public function darken(float $amount): static
Parameters
NameTypeDefault
$amount float -
public function desaturate(float $amount): static
Parameters
NameTypeDefault
$amount float -
public function equals(ColorInterface $other): bool
Parameters
NameTypeDefault
$other ColorInterface -

from

static
public static function from(ColorInterface|string $input): static
Parameters
NameTypeDefault
$input ColorInterface|string -

fromChannels

static
public static function fromChannels(array $channels, float $alpha): static

Create color from channel values.

Parameters
NameTypeDefault
$channels array -
$alpha float 1

fromHsl

static
public static function fromHsl(array $hsl, float $alpha): SrgbColor

Create an sRGB color from HSL components.

Parameters
NameTypeDefault
$hsl array -
$alpha float 1

fromSrgb

static
public static function fromSrgb(SrgbColor $srgb): static
Parameters
NameTypeDefault
$srgb SrgbColor -
public function getAlpha(): float
public function getBlue(): float

Get the blue component value (0 to 1).

public function getChannels(): array
public function getGreen(): float

Get the green component value (0 to 1).

public function getHslChannels(): array

Read the color as HSL channels.

HSL is a cylindrical notation of sRGB, not a separate color space, so this
returns channel values rather than a color object.

public function getHue(): float
public function getLuminance(): float
public function getOpacity(): float
public function getRed(): float

Get the red component value (0 to 1).

public function getSaturation(): float

getSpaceName

static
public static function getSpaceName(): string
public function grayscale(): static
public function invert(): static
public function isCold(): bool
public function isDark(): bool
public function isHot(): bool
public function isLight(): bool
public function isOpaque(): bool
public function isTransparent(): bool
public function lighten(float $amount): static
Parameters
NameTypeDefault
$amount float -

parse

static
public static function parse(string $color): static

Parse an RGB or hex color string into an sRGB color instance.

Supports: rgb(r g b), rgba(r,g,b,a), rgb(r g b / a), #RGB, #RGBA, #RRGGBB, #RRGGBBAA.

Parameters
NameTypeDefault
$color string -

parseHex

static
public static function parseHex(string $hex): static

Parse a hexadecimal color string into an sRGB color instance.

Parameters
NameTypeDefault
$hex string -

parseHsl

static
public static function parseHsl(string $color): static

Parse an HSL or HSLA color string into an sRGB color instance.

Parameters
NameTypeDefault
$color string -
public function rotateHue(float $degrees): static
Parameters
NameTypeDefault
$degrees float -
public function saturate(float $amount): static
Parameters
NameTypeDefault
$amount float -
public function shade(float $t): static
Parameters
NameTypeDefault
$t float -
public function splitComplementary(): array
public function temperature(): float
public function tetradic(): array
public function tint(float $t): static
Parameters
NameTypeDefault
$t float -

to

public function to(ColorInterface|string $space): ColorInterface
Parameters
NameTypeDefault
$space ColorInterface|string -
public function toCss(string $space): string
Parameters
NameTypeDefault
$space string null
public function toHex(bool $withAlpha): string
Parameters
NameTypeDefault
$withAlpha bool false
public function toHsl(): array

Read the color as HSL channels.

public function toOklch(): OklchColor
public function toSrgb(): SrgbColor
public function toString(): string
public function triadic(): array

tryFrom

static
public static function tryFrom(ColorInterface|string $input): static
Parameters
NameTypeDefault
$input ColorInterface|string -
public function warm(float $amount): static
Parameters
NameTypeDefault
$amount float -
public function withAlpha(float $alpha): static
Parameters
NameTypeDefault
$alpha float 1
public function withChannel(string $name, int|float $value): static
Parameters
NameTypeDefault
$name string -
$value int|float -
public function withChannels(array $partial): static
Parameters
NameTypeDefault
$partial array -