Created
May 2, 2012 20:16
-
-
Save apapirovski/2580052 to your computer and use it in GitHub Desktop.
Calculate luma (brightness) of a hexadecimal colour
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
// Calculate luma (brightness) of a hexadecimal colour | |
// --------------------------------------------------- | |
// You can use this to calculate whether two colours | |
// are suitable to be used as a background and text | |
function hex2luma(hex) { | |
return ( | |
(parseInt(hex.substring(0, 2), 16) * 299) + | |
(parseInt(hex.substring(2, 4), 16) * 587) + | |
(parseInt(hex.substring(4, 6), 16) * 114) | |
) / 1000; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment