Created
August 8, 2012 14:45
-
-
Save matthewkremer/3295567 to your computer and use it in GitHub Desktop.
Python Hex Code to RGB Value
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): | |
hex = hex.lstrip('#') | |
hlen = len(hex) | |
return tuple(int(hex[i:i+hlen/3], 16) for i in range(0, hlen, hlen/3)) |
What about from hex to RGB (.00 - 1.00)?
** Edit - Sorry, it was easy to figure out after a second.
def getRGBdecr(hex):
hex = hex.lstrip('#')
hlen = len(hex)
return tuple(int(hex[i:i+hlen/3], 16) / 255.0 for i in range(0, hlen, hlen/3))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Python 3.7