Warning: Invalid argument supplied for foreach() in /home/jihswbiz/public_html/t6.gwilt.org/refDox.php on line 212
Docs-colorDarkness

 

ReLoad

Keys


Functions

arraybrowsercolorcookiedatetimeDBdebugdeviceDSTequiverrorflagsfontformatgeo
holidayhtmlisjsonmathparsePHPprintsearchsortstringtabletexttracetype
VOTDweatherxml

Function  colorDarkness   Lines 511-536 (25 lines)Updated: 2021-02-18 file  utils.php   Last mod: Fri 2021-05-14 21:45:07

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] = sqrt0.241*$r*$r 0.691*$g*$g 0.068*$b*$b )/255;   #       Luminance (perceived approach 3)
        
$ar[3] = sqrt0.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;
        }

?>