CIE XYZ

The device-independent reference every conversion passes through.

Channels
  • X X 0 to ~0.95
  • Y Y (luminance) 0 to 1
  • Z Z 0 to ~1.09
CSS syntax
color(xyz ...), color(xyz-d65 ...)
White point
D65
Category
Foundation
PHP class
XyzColor
Reach for it when
Colorimetry, adaptation, conversion plumbing.

Convert to CIE XYZ in PHP

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

<?php

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

$color->getChannels();
// ['x' => 0.2641, 'y' => 0.2355, 'z' => 0.9032]
$color = Color::parse('#3b82f6')->to('xyz-d65'); $color->getChannels(); // ['x' => 0.2641, 'y' => 0.2355, 'z' => 0.9032]

Parse CIE XYZ in PHP

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

<?php

$color = Color::parse('color(xyz-d65 0.21 0.22 0.92)');

$color->toHex(); // #0088f8
$color = Color::parse('color(xyz-d65 0.21 0.22 0.92)'); $color->toHex(); // #0088f8

Export CIE XYZ in CSS

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

<?php

Color::parse('#3b82f6')->to('xyz-d65')->toCss();
// color(xyz-d65 0.264148 0.235458 0.903236)
Color::parse('#3b82f6')->to('xyz-d65')->toCss(); // color(xyz-d65 0.264148 0.235458 0.903236)

Validate CIE XYZ

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

<?php

Color::tryFrom('color(xyz-d65 0.21 0.22 0.92)'); // instance

Color::tryFrom('color(nope)'); // null
Color::tryFrom('color(xyz-d65 0.21 0.22 0.92)'); // instance Color::tryFrom('color(nope)'); // null