lcms2.to_hex

to_hex(rgb: Any) → str | list[str][source]

Format sRGB floats in 0..1 as "#rrggbb" ("#rrggbbaa" with alpha).

Parameters:

rgb (array_like, shape (3,), (4,) or (N, 3|4)) – Colours as floats in 0..1; out-of-range values are clipped.

Returns:

str or list of str – One string for a single colour, a list for an array of colours.

Examples

>>> from lcms2._parse import to_hex
>>> to_hex([1.0, 0.5, 0.0])
'#ff8000'
>>> to_hex([[0, 0, 0], [1, 1, 1]])
['#000000', '#ffffff']