Need a quick chart or graph for your blog? Try our reStructured Text renderer.
Join Siafoo Now
or
Learn More
Hex2RGB
0
| In Brief | This function converts a hex color triplet, like those found in HTML or CSS, and converts it to a Python 3-integer tuple. I've found it to be useful for more than one program. |
| Language | Python |
# 's
1def hex2rgb(hexColor):
2 if hexColor[0] == '#': hexColor = hexColor[1:]
3 elif hexColor[0:2].lower() == '0x': hexColor = hexColor[2:]
4 if len(hexColor) < 6: hexColor = hexColor[0]+'0'+hexColor[1]+'0'+hexColor[2]+'0'
5 return int(hexColor[0:2], 16), int(hexColor[2:4], 16), int(hexColor[4:6], 16)
This function converts a hex color triplet, like those found in HTML or CSS, and converts it to a Python 3-integer tuple. I've found it to be useful for more than one program.
Comments