Skip to content

Instantly share code, notes, and snippets.

@rodrigoalviani
Created September 15, 2015 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodrigoalviani/30a576897725b248e2cf to your computer and use it in GitHub Desktop.
Save rodrigoalviani/30a576897725b248e2cf to your computer and use it in GitHub Desktop.
Get best contrast to a given color
// rgb is a array [r, g, b]
function colorContrast (rgb) {
var r = rgb.r * 255,
g = rgb.g * 255,
b = rgb.b * 255;
var factor = (r * 299 + g * 587 + b * 114) / 1000;
return (factor >= 128) ? 'dark' : 'light';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment