Skip to content

Instantly share code, notes, and snippets.

@tedw
Created March 11, 2014 15:16
Show Gist options
  • Save tedw/9487936 to your computer and use it in GitHub Desktop.
Save tedw/9487936 to your computer and use it in GitHub Desktop.
function getContrast50(hexcolor){
return (parseInt(hexcolor, 16) > 0xffffff/2) ? 'black':'white';
}
function getContrastYIQ(hexcolor){
var r = parseInt(hexcolor.substr(0,2),16);
var g = parseInt(hexcolor.substr(2,2),16);
var b = parseInt(hexcolor.substr(4,2),16);
var yiq = ((r*299)+(g*587)+(b*114))/1000;
return (yiq >= 128) ? 'black' : 'white';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment