You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not sure I can guarantee that this returns >= 0 and <= 255, but otherwise it works.
<?php
//// Get Brightness
// Returns a brightness value from 0 to 255
// for a given 6-digit hexadecimal color string
function get_brightness(string $hex): number {
// strip off any leading #
$hex = str_replace('#', '', $hex);
$c_r = hexdec(substr($hex, 0, 2));
$c_g = hexdec(substr($hex, 2, 2));
$c_b = hexdec(substr($hex, 4, 2));
return ( ($c_r * 299) + ($c_g * 587) + ($c_b * 114) ) / 1000;
}
Constructing an equivalent in JavaScript shouldn't be too difficult.
I assume this will require some JavaScript magic to identify when something has too little contrast.
The text was updated successfully, but these errors were encountered: