-
-
Save valdemarua/76f371cf471785b098453e2bef55f293 to your computer and use it in GitHub Desktop.
calculate contrast color in Ruby
This file contains 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
def convert_to_brightness_value(background_hex_color) | |
(background_hex_color.scan(/../).map {|color| color.hex}).sum | |
end | |
def contrasting_text_color(background_hex_color) | |
convert_to_brightness_value(background_hex_color) > 382.5 ? '#000' : '#fff' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment