Last active
February 14, 2017 11:39
-
-
Save m4scosta/7857017349112b1edd08356ba75d4392 to your computer and use it in GitHub Desktop.
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
// http://stackoverflow.com/a/5624139/6111717 | |
function hexToRgb(hex) { | |
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); | |
return result ? { | |
r: parseInt(result[1], 16), | |
g: parseInt(result[2], 16), | |
b: parseInt(result[3], 16) | |
} : null; | |
} | |
// http://stackoverflow.com/a/3943023/6111717 | |
function chooseBlackWhiteFontColor(backgroundColor) { | |
var rgb = hexToRgb(backgroundColor); | |
var luminance = 0.2126 * rgb.r + 0.7152 * rgb.g + 0.0722 * rgb.b; | |
return luminance > 0.179 ? '#000000' : '#FFFFFF'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment