Color Conversion

Move between color models without losing track of channels, gamut, or intent.

Choose a color space

Compare the coordinate systems PHPColor supports and select the right one for the operation.

Explore Spaces
sRGB OKLCH Display P3 CIE Lab Rec. 2020

Convert between spaces

Translate colors across perceptual, display, print, and connection spaces through one API.

Explore Conversion
<?php

use PhpColor\Color\Color;

$color = Color::parse('#3b82f6');

$oklch = $color->to('oklch');
$p3 = $color->to('display-p3');
use PhpColor\Color\Color; $color = Color::parse('#3b82f6'); $oklch = $color->to('oklch'); $p3 = $color->to('display-p3');

Inspect color channels

Choose a working space and expose its channel names, values, and alpha as typed numeric data.

Explore Channels
LLightness · 0.62
CChroma · 0.19
HHue · 260°
AAlpha · 1.0

Measure relative luminance

Read the WCAG relative luminance of any supported color through its linearized sRGB channels.

Explore Luminance
#806eae0.187970

Check color gamuts

Test a color against an RGB gamut and measure channel overflow before choosing an output policy.

Explore Gamut
<?php

use PhpColor\Color\Color;
use PhpColor\Color\Colorimetry\Gamut;

$color = Color::parse('color(display-p3 1 0.2 0.1)');
$fits = Gamut::isInGamut(
    $color,
    'srgb',
);
use PhpColor\Color\Color; use PhpColor\Color\Colorimetry\Gamut; $color = Color::parse('color(display-p3 1 0.2 0.1)'); $fits = Gamut::isInGamut( $color, 'srgb', );

Adapt color white points

Adapt a color between reference whites with Bradford or CAT16 while preserving its type and alpha.

Explore White points
D50BradfordD65

Keep building

Move through color spaces with intent