Inspect color channels
Choose a working space and expose its channel names, values, and alpha as typed numeric data.
- Lightness
- 0.581141
- Chroma
- 0.097916
- Hue
- 296.153606
See the coordinates behind a visible color
Convert into the space your calculation expects, then read a stable set of named channels. Alpha remains available beside the coordinates.
Ask for the space before asking for its channels
The conversion makes the channel schema explicit. The same object contract then returns the numeric values without CSS formatting or string parsing.
<?php
use PhpColor\Color\Color;
$color = Color::parse('#806eae')->to('oklch');
$channels = $color->getChannels();
echo $channels['l']; // 0.58114144057732908
echo $channels['c']; // 0.09791629290853478
echo $channels['h']; // 296.1536063577542
use PhpColor\Color\Color;
$color = Color::parse('#806eae')->to('oklch');
$channels = $color->getChannels();
echo $channels['l']; // 0.58114144057732908
echo $channels['c']; // 0.09791629290853478
echo $channels['h']; // 296.1536063577542
Use inspected values without losing the source color
Channel data can feed storage, diagnostics, or a deliberate immutable update. The original object remains available for comparison and output.
Source - L 0.581
Derived - L 0.72
Use exact keys and validate the resulting color
Channel updates recognize only keys in the current space. An unknown key throws an InvalidArgumentException. Direct coordinate changes also do not prove that the result fits a target gamut.
<?php
use PhpColor\Color\Color;
$source = Color::parse('#806eae')->to('oklch');
try {
$source->withChannel('red', 1);
} catch (\InvalidArgumentException $error) {
echo $error->getMessage();
}
use PhpColor\Color\Color;
$source = Color::parse('#806eae')->to('oklch');
try {
$source->withChannel('red', 1);
} catch (\InvalidArgumentException $error) {
echo $error->getMessage();
}