Color Conversion
Convert between perceptual, display, print, and connection spaces through one typed API.
sRGBrgb(128 110 174)OKLCHoklch(0.581141 0.0979163 296.154)Display P3color(display-p3 0.491213 0.433759 0.666815)One source becomes typed destination objects
The visible color remains recognizable while its class, channel schema, and native CSS representation change with the selected space.
Convert with one stable method
Call to() with a canonical space name. The returned object exposes the destination’s channels while the original color remains unchanged.
<?php
use PhpColor\Color\Color;
$source = Color::parse('#806eae');
$oklch = $source->to('oklch');
$lab = $source->to('lab');
$p3 = $source->to('display-p3');
$cmyk = $source->to('cmyk');
use PhpColor\Color\Color;
$source = Color::parse('#806eae');
$oklch = $source->to('oklch');
$lab = $source->to('lab');
$p3 = $source->to('display-p3');
$cmyk = $source->to('cmyk');
Choose the space that suits the operation
Use perceptual coordinates for visual adjustments, RGB spaces for display targets, XYZ as a connection space, and CMYK when the workflow needs subtractive channels.
Let PHPColor handle the conversion path
A conversion may linearize RGB, pass through XYZ, adapt reference whites, and enter perceptual coordinates. The public API keeps that pipeline behind the destination name.
Convert a complete palette in one operation
Palette conversion preserves order and names while replacing every member with the requested destination-space object.
<?php
use PhpColor\Color\Palette\ColorPalette;
$palette = ColorPalette::parse([
'#1d4ed8', '#3b82f6', '#93c5fd',
]);
$oklch = $palette->to('oklch');
$css = $oklch->toCss();
use PhpColor\Color\Palette\ColorPalette;
$palette = ColorPalette::parse([
'#1d4ed8', '#3b82f6', '#93c5fd',
]);
$oklch = $palette->to('oklch');
$css = $oklch->toCss();