Keys →
Functions ↓
function colorDarkness ( $col ) {#-k color#- given a hex color, what is its relative darkness?#-p $col - req - Hex RGB color (Must be in the form #hhhhhh)#-p - ret - Array 0..4 entries of different interpretations of darkness, each (float) 0..1; 0 is white up to 1 black#-c credit: http://stackoverflow.com/questions/1855884/determine-font-color-based-on-background-color#-c credit#3: http://stackoverflow.com/questions/596216/formula-to-determine-brightness-of-rgb-color#-d 2/18/21 Fixed $r = 255 - hexdec ( substr($col,1,2) ); $g = 255 - hexdec ( substr($col,3,2) ); $b = 255 - hexdec ( substr($col,5,2) ); $ar[0] = (0.2126*$r + 0.7152*$g + 0.0722*$b)/255; # Luminance (standard, objective) $ar[1] = ( 0.299*$r + 0.587*$g + 0.114*$b)/255; # Luminance (perceived approach 1) $ar[2] = sqrt( 0.241*$r*$r + 0.691*$g*$g + 0.068*$b*$b )/255; # Luminance (perceived approach 3) $ar[3] = sqrt( 0.299*$r*$r + 0.587*$g*$g + 0.114*$b*$b )/255; # Luminance (perceived approach 3) if (($r>128)&&($g>128)&&($b>128)) $m = 1.0; # def light elseif (($r<128)&&($g<128)&&($b<128)) $m = 0.5; # def dark $ar[4] = $ar[3]*(1+$m)/2; $ar[4] = 1-colorRelativeLuminance($col); return $ar; }?>