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

 

ReLoad

Keys


Functions

arraybrowsercolorcookiedatetimeDBdebugdeviceDSTequiverrorflagsfontformatgeo
holidayhtmlisjsonmathparsePHPprintsearchsortstringtabletexttracetype
VOTDweatherxml

Function  colorRelativeLuminance   Lines 570-598 (28 lines)Added: 2021-02-19 file  utils.php   Last mod: Fri 2021-05-14 21:45:07

function colorRelativeLuminance($col)
        {
#-k     color
#-      Calculate relative luminance in sRGB colour space for use in WCAG 2.0 compliance
#-p     $col    - req   - Hex RGB color (Must be in the form #hhhhhh)
#-p             - ret   - (float) value between 0 and 1
#-      @link http://www.w3.org/TR/WCAG20/#relativeluminancedef
#-c     @author Marcus Bointon <marcus@synchromedia.co.uk>
#-d     2/19/21 - Added

#               Remove any leading #
        
$col trim($col'#');

#           Convert hex to 0-1 scale
        
$components = array(
                
'r' => hexdec(substr($col02)) / 255,
                
'g' => hexdec(substr($col22)) / 255,
                
'b' => hexdec(substr($col42)) / 255
                        
);
#       Correct for sRGB
        
foreach($components as $c => $v)
                {
                if (
$v <= 0.04045)      { $components[$c] = $v 12.92; }
                else                    { 
$components[$c] = pow((($v 0.055) / 1.055), 2.4); }
                }
#       Calculate relative luminance using ITU-R BT. 709 coefficients
        
return ($components['r'] * 0.2126) + ($components['g'] * 0.7152) + ($components['b'] * 0.0722);
        }

?>