Created
December 26, 2014 06:21
-
-
Save xhinking/e362ff63d62b6593dc03 to your computer and use it in GitHub Desktop.
Determine if the given hex color is light or dark. Helpful to determining foreground color against a background color.
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
// https://github.com/scottcorgan/contrast | |
var hexToRgb = require('hex-to-rgb'); | |
module.exports = function contrast (hex) { | |
var rgb = hexToRgb(hex); | |
var o = Math.round(((parseInt(rgb[0]) * 299) + (parseInt(rgb[1]) * 587) + (parseInt(rgb[2]) * 114)) /1000); | |
return (o <= 180) ? 'dark' : 'light'; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment