Linear sRGB

sRGB without gamma encoding: light behaves like light.

Channels
  • R Red 0 to 1
  • G Green 0 to 1
  • B Blue 0 to 1
CSS syntax
color(srgb-linear ...)
White point
D65
Category
RGB
PHP class
LinearSrgbColor
Reach for it when
Physically correct blending and compositing.

Convert to Linear sRGB in PHP

Any color converts with to(); the result is Linear sRGB, an object with its own channels.

<?php

$color = Color::parse('#3b82f6')->to('srgb-linear');

$color->getChannels();
// ['r' => 0.0437, 'g' => 0.2232, 'b' => 0.9216]
$color = Color::parse('#3b82f6')->to('srgb-linear'); $color->getChannels(); // ['r' => 0.0437, 'g' => 0.2232, 'b' => 0.9216]

Parse Linear sRGB in PHP

The regular CSS syntax goes straight into Color::parse().

<?php

$color = Color::parse('color(srgb-linear 0.045 0.226 0.936)');

$color->toHex(); // #3c83f8
$color = Color::parse('color(srgb-linear 0.045 0.226 0.936)'); $color->toHex(); // #3c83f8

Export Linear sRGB in CSS

Every color object serializes back to the CSS form of its space.

<?php

Color::parse('#3b82f6')->to('srgb-linear')->toCss();
// color(srgb-linear 0.043735 0.223228 0.921582)
Color::parse('#3b82f6')->to('srgb-linear')->toCss(); // color(srgb-linear 0.043735 0.223228 0.921582)

Validate Linear sRGB

tryFrom() returns null on invalid input instead of throwing.

<?php

Color::tryFrom('color(srgb-linear 0.045 0.226 0.936)'); // instance

Color::tryFrom('color(nope)'); // null
Color::tryFrom('color(srgb-linear 0.045 0.226 0.936)'); // instance Color::tryFrom('color(nope)'); // null