Skip to content

Instantly share code, notes, and snippets.

@danhollick
Created February 3, 2020 17:16
Show Gist options
  • Save danhollick/8b3fe09abfdb0a05294f07c35184e0f3 to your computer and use it in GitHub Desktop.
Save danhollick/8b3fe09abfdb0a05294f07c35184e0f3 to your computer and use it in GitHub Desktop.
Check alpha
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