Skip to content

Instantly share code, notes, and snippets.

@jfriedlaender
Created October 9, 2011 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfriedlaender/1273620 to your computer and use it in GitHub Desktop.
Save jfriedlaender/1273620 to your computer and use it in GitHub Desktop.
Get contrasting color
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