Last active
December 5, 2016 11:41
-
-
Save friedemannsommer/e2923a6e0c5a865e5ae410d427b61624 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
/** | |
* @url http://stackoverflow.com/questions/1855884/determine-font-color-based-on-background-color | |
* @url http://stackoverflow.com/questions/596216/formula-to-determine-brightness-of-rgb-color | |
**/ | |
function perceptiveLuminance(color) { | |
return 1 - (0.299 * color.r + 0.587 * color.g + 0.114 * color.b) / 255 | |
} | |
function getFontColor(backgroundColor) { | |
if (perceptiveLuminance(backgroundColor) < 0.5) { | |
return { | |
r: 0, | |
g: 0, | |
b: 0 | |
} | |
} else { | |
return { | |
r: 255, | |
g: 255, | |
b: 255 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment