Created
September 15, 2015 19:02
-
-
Save rodrigoalviani/30a576897725b248e2cf to your computer and use it in GitHub Desktop.
Get best contrast to a given color
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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