Base class for all color space implementations.
public function analogous(int $count): array
Parameters
| Name | Type | Default |
$count |
int |
2 |
public function blend(ColorInterface|string $backdrop, string $mode): static
Parameters
| Name | Type | Default |
$backdrop |
ColorInterface|string |
- |
$mode |
string |
"normal" |
public function complementary(): static
public function cool(float $amount): static
Parameters
| Name | Type | Default |
$amount |
float |
- |
public function darken(float $amount): static
Parameters
| Name | Type | Default |
$amount |
float |
- |
public function desaturate(float $amount): static
Parameters
| Name | Type | Default |
$amount |
float |
- |
public function equals(ColorInterface $other): bool
Parameters
| Name | Type | Default |
$other |
ColorInterface |
- |
public static function from(ColorInterface|string $input): static
Parameters
| Name | Type | Default |
$input |
ColorInterface|string |
- |
public static function fromSrgb(SrgbColor $srgb): static
Parameters
| Name | Type | Default |
$srgb |
SrgbColor |
- |
public function getAlpha(): float
public function getChannels(): array
Get the color channel values as an associative array.
Returns the color's channel values in its native color space. The channel names
and value ranges depend on the color space:
- sRGB: ['r', 'g', 'b'] (0-1)
- Oklab: ['l', 'a', 'b'] (l: 0-1, a/b: unbounded)
- Oklch: ['l', 'c', 'h'] (l: 0-1, c: 0+, h: 0-360)
- Lab: ['l', 'a', 'b'] (l: 0-100, a/b: unbounded)
- Lch: ['l', 'c', 'h'] (l: 0-100, c: 0+, h: 0-360)
- XYZ: ['x', 'y', 'z'] (unbounded)
- Display P3: ['r', 'g', 'b'] (0-1)
The alpha channel is accessed separately via getAlpha().
This is particularly useful for CSS Relative Color Syntax or custom color
manipulations where you need direct access to channel values.
Examples:
- Color::parse('red')->getChannels() // ['r' => 1.0, 'g' => 0.0, 'b' => 0.0]
- Color::parse('oklab(0.5 0.1 -0.2)')->getChannels() // ['l' => 0.5, 'a' => 0.1, 'b' => -0.2]
public function getHue(): float
public function getLuminance(): float
public function getOpacity(): float
public function getSaturation(): float
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
| Name | Type | Default |
$amount |
float |
- |
public function rotateHue(float $degrees): static
Parameters
| Name | Type | Default |
$degrees |
float |
- |
public function saturate(float $amount): static
Parameters
| Name | Type | Default |
$amount |
float |
- |
public function shade(float $t): static
Parameters
| Name | Type | Default |
$t |
float |
- |
public function splitComplementary(): array
public function temperature(): float
public function tetradic(): array
public function tint(float $t): static
Parameters
| Name | Type | Default |
$t |
float |
- |
public function to(ColorInterface|string $space): ColorInterface
Parameters
| Name | Type | Default |
$space |
ColorInterface|string |
- |
public function toCss(string $space): string
Generate CSS color function output.
Returns a CSS-compatible color string. The output format depends on the space parameter:
- null (auto): Uses the most appropriate format for this color space
- 'srgb' or 'rgb': rgb() function
- 'hsl': hsl() function (for sRGB colors)
- 'color': color() function with explicit color space
- 'oklab', 'oklch', 'lab', 'lch': Respective CSS color functions
Examples:
- ->toCss() => 'rgb(255 0 0)' or 'oklab(0.628 0.225 0.126)'
- ->toCss('hsl') => 'hsl(0 100% 50%)'
- ->toCss('srgb') => 'rgb(255 0 0)'
- ->toCss('color') => 'color(srgb 1 0 0)'
Alpha channel is included in output when not fully opaque (< 1.0):
- 'rgb(255 0 0 / 0.5)' or 'oklab(0.628 0.225 0.126 / 0.8)'
Parameters
| Name | Type | Default |
$space |
string |
null |
public function toHex(bool $withAlpha): string
Parameters
| Name | Type | Default |
$withAlpha |
bool |
false |
public function toOklch(): OklchColor
public function toSrgb(): SrgbColor
Convert to sRGB color space.
Convenience method for converting to sRGB, the most common color space for web use.
This method is used internally by many operations that need to work in sRGB space.
public function toString(): string
public function triadic(): array
public static function tryFrom(ColorInterface|string $input): static
Parameters
| Name | Type | Default |
$input |
ColorInterface|string |
- |
public function warm(float $amount): static
Parameters
| Name | Type | Default |
$amount |
float |
- |
public function withAlpha(float $alpha): static
Parameters
| Name | Type | Default |
$alpha |
float |
1 |
public function withChannel(string $name, int|float $value): static
Parameters
| Name | Type | Default |
$name |
string |
- |
$value |
int|float |
- |
public function withChannels(array $partial): static
Parameters
| Name | Type | Default |
$partial |
array |
- |