LCH

CIE Lab in polar form: lightness, chroma, hue.

Channels
  • L Lightness 0 to 100
  • C Chroma 0 to ~130
  • H Hue 0 to 360
CSS syntax
lch()
White point
D65 in PHPColor; CSS lch() uses D50
Category
Cylindrical
PHP class
LchColor
Reach for it when
Hue-aware manipulation on the CIE side.

Convert to LCH in PHP

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

<?php

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

$color->getChannels();
// ['l' => 54.6185, 'c' => 66.3715, 'h' => 277.5888]
$color = Color::parse('#3b82f6')->to('lch'); $color->getChannels(); // ['l' => 54.6185, 'c' => 66.3715, 'h' => 277.5888]

Parse LCH in PHP

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

<?php

$color = Color::parse('lch(55 65 277)');

$color->toHex(); // #3d83f5
$color = Color::parse('lch(55 65 277)'); $color->toHex(); // #3d83f5

Export LCH in CSS

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

<?php

Color::parse('#3b82f6')->to('lch')->toCss();
// lch(54.6185 66.3715 277.589)
Color::parse('#3b82f6')->to('lch')->toCss(); // lch(54.6185 66.3715 277.589)

Validate LCH

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

<?php

Color::tryFrom('lch(55 65 277)'); // instance

Color::tryFrom('lch(nope)'); // null
Color::tryFrom('lch(55 65 277)'); // instance Color::tryFrom('lch(nope)'); // null