Keys →
Functions ↓
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($col, 0, 2)) / 255, 'g' => hexdec(substr($col, 2, 2)) / 255, 'b' => hexdec(substr($col, 4, 2)) / 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); }?>