Is Light Color

Check if a hex color is light (good for determining text color).

Code

General
$h = ltrim($hex, '#');
$r = hexdec(substr($h, 0, 2));
$g = hexdec(substr($h, 2, 2));
$b = hexdec(substr($h, 4, 2));
return ($r * 0.299 + $g * 0.587 + $b * 0.114) > 186;

Parameters

Hex color to check

Server

More PHP Snippets