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
Hex to RGB
Convert a hex color code to RGB values.
Random Hex Color
Generate a random hexadecimal color code for use in CSS or graphics applications.
RGB to Hex
Convert RGB color values (0-255) to a hexadecimal color code.
Array Difference
Find elements in the first array that are not present in the second array.
Array Frequencies
Count how many times each value appears in an array and return a frequency map.
Array Head
Get the first n elements of an array.