Created
September 30, 2011 14:05
-
-
Save sevas/1253835 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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