Created
October 25, 2018 10:19
-
-
Save maulerjan/249c66b3ce7cb9817ecc99b93acea365 to your computer and use it in GitHub Desktop.
Get color brightness (from hexa)
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
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