Module: ColorContrastCalc::TransparencyCalc
- Includes:
- Converter::AlphaCompositing::Rgba
- Defined in:
- lib/color_contrast_calc/transparency_calc.rb
Overview
Provides methods to calculate the contrast ratio between transparent colors.
Colors are given as RGBA values represented as arrays of Float. Note that during the process of calculation, each of RGB components is treated as a Float, though some of them may be rounded up/down in the final return value.
Constant Summary
Constants included from Converter::AlphaCompositing::Rgba
Converter::AlphaCompositing::Rgba::BLACK, Converter::AlphaCompositing::Rgba::WHITE
Class Method Summary collapse
Class Method Details
.contrast_ratio(foreground, background, base = WHITE) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/color_contrast_calc/transparency_calc.rb', line 18 def self.contrast_ratio(foreground, background, base = WHITE) colors = [foreground, background] rgb_colors = if colors.all? {|color| opaque?(color) } colors.map {|color| to_rgb(color) } else to_opaque_rgbs(foreground, background, base) end Checker.contrast_ratio(*rgb_colors) end |