Measure relative luminance
Reduce any supported color to one WCAG relative-luminance value for comparison and classification.
#806eae0.187970474941#d977060.279585140407#f8fafc0.953559478081Visible brightness becomes one comparable value
PHPColor converts each color to sRGB, linearizes its channels, and applies the WCAG coefficients. The result ranges from black at 0 to white at 1.
Use the same method for every input space
getLuminance() belongs to the common color interface. An OKLCH, Lab, or Display P3 object follows the same sRGB-based calculation path.
<?php
use PhpColor\Color\Color;
$brand = Color::parse('#806eae');
$accent = Color::parse('#d97706');
$surface = Color::parse('#f8fafc');
echo $brand->getLuminance();
// 0.187970474941...
echo $accent->getLuminance();
// 0.279585140407...
echo $surface->getLuminance();
// 0.953559478081...
use PhpColor\Color\Color;
$brand = Color::parse('#806eae');
$accent = Color::parse('#d97706');
$surface = Color::parse('#f8fafc');
echo $brand->getLuminance();
// 0.187970474941...
echo $accent->getLuminance();
// 0.279585140407...
echo $surface->getLuminance();
// 0.953559478081...
Relative luminance is not OKLCH lightness
Both describe light-related properties, but they use different models and serve different calculations. Do not substitute an OKLCH l channel for WCAG relative luminance.
Relative luminanceLinearized sRGB value used by WCAG contrast.
OKLCH lightnessPerceptual coordinate used for color manipulation.