Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get best contrast to a given color
// rgb is a array [r, g, b]
function colorContrast (rgb) {
var r = rgb.r * 255,
g = rgb.g * 255,
b = rgb.b * 255;
var factor = (r * 299 + g * 587 + b * 114) / 1000;
return (factor >= 128) ? 'dark' : 'light';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.