Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get color brightness (from hexa)
export default function getBrightness(c) {
var c = c.substring(1) // strip #
var rgb = parseInt(c, 16) // convert rrggbb to decimal
var r = (rgb >> 16) & 0xff // extract red
var g = (rgb >> 8) & 0xff // extract green
var b = (rgb >> 0) & 0xff // extract blue
var luma = (r * 299 + g * 587 + b * 114) / 1000
return luma
}
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.