Skip to content

Instantly share code, notes, and snippets.

@sevas
Created September 30, 2011 14:05
Show Gist options
  • Select an option

  • Save sevas/1253835 to your computer and use it in GitHub Desktop.

Select an option

Save sevas/1253835 to your computer and use it in GitHub Desktop.
def hex_to_rgb(hex_string_color):
"""
Convert a color encoded in an hex string into
an rgb tuple.
Example:
>> hex_to_rgb("5b6eff")
(91, 110, 255)
"""
hc = hex_string_color
if hc.startswith("#"):
hc = hc[1:]
channel_values = [hc[2*i:2*i+2] for i in range(len(hc)/2)]
return tuple([int(c, 16) for c in channel_values])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment