sRGB

The web default: every browser, every device, the baseline gamut.

Channels
  • R Red 0 to 1
  • G Green 0 to 1
  • B Blue 0 to 1
CSS syntax
rgb(), #hex, color(srgb ...)
White point
D65
Category
RGB
PHP class
SrgbColor
Reach for it when
Compatibility, hex output, legacy pipelines.

Convert to sRGB in PHP

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

<?php

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

$color->getChannels();
// ['r' => 0.2314, 'g' => 0.5098, 'b' => 0.9647]
$color = Color::parse('#3b82f6')->to('srgb'); $color->getChannels(); // ['r' => 0.2314, 'g' => 0.5098, 'b' => 0.9647]

Parse sRGB in PHP

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

<?php

$color = Color::parse('rgb(59 130 246)');

$color->toHex(); // #3b82f6
$color = Color::parse('rgb(59 130 246)'); $color->toHex(); // #3b82f6

Export sRGB in CSS

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

<?php

Color::parse('#3b82f6')->to('srgb')->toCss();
// rgb(59 130 246)
Color::parse('#3b82f6')->to('srgb')->toCss(); // rgb(59 130 246)

Validate sRGB

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

<?php

Color::tryFrom('rgb(59 130 246)'); // instance

Color::tryFrom('rgb(nope)'); // null
Color::tryFrom('rgb(59 130 246)'); // instance Color::tryFrom('rgb(nope)'); // null