Unified · Split
| @@ -105,6 +105,8 @@ class SpritesCLI < Thor · 104 unmodified lines | |||
| 105 | end | 105 | end |
| 106 | 106 | ||
| 107 | def get_contrast(base, other) | 107 | def get_contrast(base, other) |
| 108 | # Calculating the contrast ratio as described in the WCAG 2.0: | ||
| 109 | # https://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef | ||
| 108 | l1 = get_luminance(base) + 0.05 | 110 | l1 = get_luminance(base) + 0.05 |
| 109 | l2 = get_luminance(other) + 0.05 | 111 | l2 = get_luminance(other) + 0.05 |
| 110 | ratio = l1 / l2 | 112 | ratio = l1 / l2 |
| @@ -118,6 +120,9 @@ class SpritesCLI < Thor · 7 unmodified lines | |||
| 118 | ChunkyPNG::Color.b(color).to_f | 120 | ChunkyPNG::Color.b(color).to_f |
| 119 | ] | 121 | ] |
| 120 | 122 | ||
| 123 | # Calculating the relative luminance as described in the WCAG 2.0: | ||
| 124 | # https://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef | ||
| 125 | |||
| 121 | rgb.map! do |value| | 126 | rgb.map! do |value| |
| 122 | value /= 255 | 127 | value /= 255 |
| 123 | value < 0.03928 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4 | 128 | value < 0.03928 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4 |