Created
October 27, 2015 13:57
-
-
Save teamgroove/f2cfd402923a1c601fa1 to your computer and use it in GitHub Desktop.
yiq formula to define black or white text for maximum contrast automatically
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
var textColor = function (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