CIE Lab

The color-science classic: device-independent, perceptual lightness.

Channels
  • L Lightness 0 to 100
  • a Green to red -128 to 127
  • b Blue to yellow -128 to 127
CSS syntax
lab()
White point
D65 in PHPColor; CSS lab() uses D50
Category
Perceptual
PHP class
LabColor
Reach for it when
Delta E distance, print and imaging pipelines.

Convert to CIE Lab in PHP

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

<?php

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

$color->getChannels();
// ['l' => 54.6185, 'a' => 8.7652, 'b' => -65.7902]
$color = Color::parse('#3b82f6')->to('lab'); $color->getChannels(); // ['l' => 54.6185, 'a' => 8.7652, 'b' => -65.7902]

Parse CIE Lab in PHP

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

<?php

$color = Color::parse('lab(55 8 -65)');

$color->toHex(); // #3c83f6
$color = Color::parse('lab(55 8 -65)'); $color->toHex(); // #3c83f6

Export CIE Lab in CSS

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

<?php

Color::parse('#3b82f6')->to('lab')->toCss();
// lab(54.6185 8.76522 -65.7902)
Color::parse('#3b82f6')->to('lab')->toCss(); // lab(54.6185 8.76522 -65.7902)

Validate CIE Lab

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

<?php

Color::tryFrom('lab(55 8 -65)'); // instance

Color::tryFrom('lab(nope)'); // null
Color::tryFrom('lab(55 8 -65)'); // instance Color::tryFrom('lab(nope)'); // null