Last active
August 29, 2015 14:14
-
-
Save azzlack/0ff3af2973fbddeb3728 to your computer and use it in GitHub Desktop.
Gets the contrast color for 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
var getContrastColor = function(hexcolor) { | |
var hex = hexcolor.replace(/[^0-9a-f]/gi, ''); | |
var r = parseInt(hex.substr(0, 2), 16); | |
var g = parseInt(hex.substr(2, 2), 16); | |
var b = parseInt(hex.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