Rec. 2020

The HDR and broadcast target gamut.

Channels
  • R Red 0 to 1
  • G Green 0 to 1
  • B Blue 0 to 1
CSS syntax
color(rec2020 ...)
White point
D65
Category
RGB
PHP class
Rec2020Color
Reach for it when
HDR video and future-proof pipelines.

Convert to Rec. 2020 in PHP

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

<?php

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

$color->getChannels();
// ['r' => 0.3558, 'g' => 0.4555, 'b' => 0.9201]
$color = Color::parse('#3b82f6')->to('rec2020'); $color->getChannels(); // ['r' => 0.3558, 'g' => 0.4555, 'b' => 0.9201]

Parse Rec. 2020 in PHP

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

<?php

$color = Color::parse('color(rec2020 0.28 0.47 0.93)');

$color->toHex(); // #0087f8
$color = Color::parse('color(rec2020 0.28 0.47 0.93)'); $color->toHex(); // #0087f8

Export Rec. 2020 in CSS

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

<?php

Color::parse('#3b82f6')->to('rec2020')->toCss();
// color(rec2020 0.355756 0.45545 0.920052)
Color::parse('#3b82f6')->to('rec2020')->toCss(); // color(rec2020 0.355756 0.45545 0.920052)

Validate Rec. 2020

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

<?php

Color::tryFrom('color(rec2020 0.28 0.47 0.93)'); // instance

Color::tryFrom('color(nope)'); // null
Color::tryFrom('color(rec2020 0.28 0.47 0.93)'); // instance Color::tryFrom('color(nope)'); // null