Last active
July 15, 2016 00:02
-
-
Save svieira/10439604 to your computer and use it in GitHub Desktop.
YIQ Method of calculating contrast
This file contains 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
function textColor(bgColor) { | |
var r = bgColor.r * 255, | |
g = bgColor.g * 255, | |
b = bgColor.b * 255; | |
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