-
-
Save ncou/f293afefe1257cd36cc0e16e3e02f5ef to your computer and use it in GitHub Desktop.
Calculate the relative luminance, or brightness, of a color. Accepts values 0-255 for R, G, B.
This file contains hidden or 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
// from http://www.w3.org/TR/WCAG20/#relativeluminancedef | |
function relativeLuminanceW3C(R8bit, G8bit, B8bit) { | |
var RsRGB = R8bit/255; | |
var GsRGB = G8bit/255; | |
var BsRGB = B8bit/255; | |
var R = (RsRGB <= 0.03928) ? RsRGB/12.92 : Math.pow((RsRGB+0.055)/1.055, 2.4); | |
var G = (GsRGB <= 0.03928) ? GsRGB/12.92 : Math.pow((GsRGB+0.055)/1.055, 2.4); | |
var B = (BsRGB <= 0.03928) ? BsRGB/12.92 : Math.pow((BsRGB+0.055)/1.055, 2.4); | |
// For the sRGB colorspace, the relative luminance of a color is defined as: | |
var L = 0.2126 * R + 0.7152 * G + 0.0722 * B; | |
return L; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Check : http://stackoverflow.com/questions/596216/formula-to-determine-brightness-of-rgb-color/17343790
For other values