Created
February 3, 2020 17:16
-
-
Save danhollick/8b3fe09abfdb0a05294f07c35184e0f3 to your computer and use it in GitHub Desktop.
Check alpha
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
function calculateContrast(foreground, alpha, backgound) { | |
if (alpha < 1) { | |
foreground = overlay(foreground, alpha, backgound) | |
} | |
const foregroundLuminance = calculateLuminance(foreground) + 0.05 | |
const backgroundLuminance = calculateLuminance(backgound) + 0.05 | |
let contrast = foregroundLuminance / backgroundLuminance | |
if (backgroundLuminance > foregroundLuminance) { | |
contrast = 1 / contrast | |
} | |
//... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment