Determine whether a color is dark

Classify any parsed color using PHPColor's luminance-based light and dark helpers.

Parse the value and call the semantic luminance helpers:

use PhpColor\Color\Color;

$color = Color::parse('#3b82f6');

var_dump($color->isDark());
var_dump($color->isLight());
echo $color->getLuminance();
use PhpColor\Color\Color; $color = Color::parse('#3b82f6'); var_dump($color->isDark()); var_dump($color->isLight()); echo $color->getLuminance();

PHPColor classifies a color as light when its WCAG relative luminance is at least 0.179. isDark() is the inverse. Do not replace this with a 0.5 luminance threshold: relative luminance is not perceptually centred at 0.5.

Light or dark is only a coarse classification. Use Measure WCAG contrast when choosing text or validating a foreground/background pair.