Created
October 9, 2011 12:21
-
-
Save jfriedlaender/1273620 to your computer and use it in GitHub Desktop.
Get contrasting color
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 contrasting_text_color(hex_color) | |
color = hex_color.gsub('#','') | |
convert_to_brightness_value(color) > 382.5 ? darken_color(color) : lighten_color(color) | |
end | |
def convert_to_brightness_value(hex_color) | |
(hex_color.scan(/../).map {|color| color.hex}).sum | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment