Last active
April 16, 2024 01:03
-
-
Save hsingtism/2a150db7f73ce49b6f8401dfb4e4f852 to your computer and use it in GitHub Desktop.
A function that calculates if text color should be black given a background color. (W3C compliant for all values)
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
function useBlack(r, g, b) { | |
const e = v => Math.pow(v / 255 + 0.055, 2.4) | |
r < 11 ? r /= 15496 : r = e(r) / 5.348631 | |
g < 11 ? g /= 4606. : g = e(g) / 1.589931 | |
b < 11 ? b /= 45631 : b = e(b) / 15.74957 | |
return r + g + b > 0.17912878 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment