Color Gamut

Measure sRGB overflow, then prepare wide-gamut color with deliberate browser fallbacks.

sRGBoutside by 0.057420
Display P3inside
Rec. 2020inside

The same color crosses one gamut boundary

oklch(0.65 0.208 145) exceeds sRGB through a negative red channel, while its Display P3 and Rec. 2020 coordinates remain inside their ranges.

Check whether a color fits sRGB

Ask whether a color’s converted sRGB channels fit the conventional web range before choosing an output format or building a fallback.

<?php

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

$color = Color::parse('oklch(0.65 0.208 145)');

$inSrgb = Gamut::isInGamut($color, 'srgb');
use PhpColor\Color\Color; use PhpColor\Color\Colorimetry\Gamut; $color = Color::parse('oklch(0.65 0.208 145)'); $inSrgb = Gamut::isInGamut($color, 'srgb');

Measure how far sRGB channels extend past the boundary

The sRGB gamut delta gives quality tooling more context than a boolean alone. Use it to classify values, report them, or choose a fallback policy.

0.000Every target channel is inside its range.
0.057420The demonstrated sRGB channel overflow.
<?php

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

$color = Color::parse('oklch(0.65 0.208 145)');
$overflow = Gamut::gamutDelta($color, 'srgb');

if ($overflow > 0.0) {
    // Select the output policy for this application.
}
use PhpColor\Color\Color; use PhpColor\Color\Colorimetry\Gamut; $color = Color::parse('oklch(0.65 0.208 145)'); $overflow = Gamut::gamutDelta($color, 'srgb'); if ($overflow > 0.0) { // Select the output policy for this application. }

Keep Display P3 output where the consumer supports it

Convert to Display P3 and serialize the typed result as a color(display-p3 …) value. The source stays available for any additional output target.

<?php

use PhpColor\Color\Color;

$color = Color::parse('oklch(0.65 0.208 145)');
$p3 = $color->to('display-p3');

echo $p3->toCss();
// color(display-p3 ...)
use PhpColor\Color\Color; $color = Color::parse('oklch(0.65 0.208 145)'); $p3 = $color->to('display-p3'); echo $p3->toCss(); // color(display-p3 ...)

Publish an sRGB value alongside the wider color

Generate the conventional sRGB representation required by the application, then layer the Display P3 value where the CSS environment supports it.

<?php

use PhpColor\Color\Color;

$color = Color::parse('oklch(0.65 0.208 145)');
$fallback = $color->to('srgb');
$wide = $color->to('display-p3');

echo $fallback->toHex();
echo $wide->toCss();
use PhpColor\Color\Color; $color = Color::parse('oklch(0.65 0.208 145)'); $fallback = $color->to('srgb'); $wide = $color->to('display-p3'); echo $fallback->toHex(); echo $wide->toCss();

Go deeper

Prepare precise color for its target gamut