Convert a complete palette
Move every entry to one working space without detaching names from colors.
sRGB
ink
paper
accent
OKLCH
ink
paper
accent
ink oklch(...)
paper oklch(...)
accent oklch(...)
Change coordinates and keep the collection identity
The converted palette retains ink, paper, and accent in the same order. Each value becomes an OklchColor object.
Convert every entry with one call
to() maps the requested conversion across the palette and returns a new collection.
<?php
use PhpColor\Color\Palette\ColorPalette;
$palette = ColorPalette::parse([
'ink' => '#111827',
'paper' => '#f8fafc',
'accent' => '#7c3aed',
]);
$oklch = $palette->to('oklch');
foreach ($oklch->toCss() as $name => $css) {
printf("%s %s\n", $name, $css);
}
// ink oklch(0.210084 0.0317626 264.665)
// paper oklch(0.984152 0.00341267 247.858)
// accent oklch(0.541337 0.246586 293.009)
use PhpColor\Color\Palette\ColorPalette;
$palette = ColorPalette::parse([
'ink' => '#111827',
'paper' => '#f8fafc',
'accent' => '#7c3aed',
]);
$oklch = $palette->to('oklch');
foreach ($oklch->toCss() as $name => $css) {
printf("%s %s\n", $name, $css);
}
// ink oklch(0.210084 0.0317626 264.665)
// paper oklch(0.984152 0.00341267 247.858)
// accent oklch(0.541337 0.246586 293.009)
Conversion does not choose the final format
The working-space objects and the serialized CSS strings are separate boundaries. Choose precision and gamut policy when you serialize.
NamesNamed keys remain attached to their colors.
OrderPalette order remains unchanged.
TypesEach entry becomes the requested color-space object.
SerializationtoCss() formats the converted values afterward.