3 ms·
Why the extra method for converting to brightness? Why not just this: def contrasting_text_color(background_hex_color) (background_hex_color.scan(/../).map {
by bradleyland 16y ago
Why the extra method for converting to brightness? Why not just this:
def contrasting_text_color(background_hex_color)
(background_hex_color.scan(/../).map {|color| color.hex}).sum > 382.5 ? '#000' : '#fff'
end
- charliepark 16y agoCould certainly do it that way, if you don't need the brightness value. We have a color picker that sorts a hash of "available" hexadecimal colors by their brightness value, though, so we needed to have it available as an independent method.