Skip to content

Instantly share code, notes, and snippets.

@thejefflarson
Created May 8, 2013 01:56
Show Gist options
  • Select an option

  • Save thejefflarson/5537651 to your computer and use it in GitHub Desktop.

Select an option

Save thejefflarson/5537651 to your computer and use it in GitHub Desktop.
var lum = function(hex) {
var bits = hex.match(/([0-9a-f]{2})/ig).map(function(i){
var it = parseInt(i, 16) / 255;
if(it < 0.03928)
return it / 12.92;
else
return Math.pow((it + 0.055) / 1.055, 2.4);
});
return 0.2126 * bits[0] + 0.7152 * bits[1] + 0.0722 * bits[2];
};
var ratioTest = function(bg, fg) {
return (lum(bg) + 0.05) / (lum(fg) + 0.05) > 4.5;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment