colour.conversions.web2hex¶
- colour.conversions.web2hex(web: str, force_long: bool = False) str¶
Convert WEB representation to HEX.
- Parameters
rgb – web string representation (human readable if possible)
- Return type
3 hex char or 6 hex char string representation
WEB representation uses X11 rgb.txt to define conversion between RGB and english color names.
>>> from colour import web2hex, Color
>>> web2hex('red') '#f00'
>>> web2hex('#aaa') '#aaa'
>>> web2hex('#foo') Traceback (most recent call last): ... AttributeError: '#foo' is not in web format. Need 3 or 6 hex digit.
>>> web2hex('#aaa', force_long=True) '#aaaaaa'
>>> web2hex('#aaaaaa') '#aaaaaa'
>>> web2hex('#aaaa') Traceback (most recent call last): ... AttributeError: '#aaaa' is not in web format. Need 3 or 6 hex digit.
>>> web2hex('pinky') Traceback (most recent call last): ... ValueError: 'pinky' is not a recognized color.
And color names are case insensitive:
>>> Color('RED') <Color red>