lcms2.parse_color¶
- parse_color(value: Any) ndarray[source]¶
Parse one colour into sRGB floats in 0..1.
- Parameters:
value (str or sequence or ndarray) –
"#rgb","#rgba","#rrggbb","#rrggbbaa", a CSS4 colour name (case-insensitive),"rgb(...)"/"rgba(...)"(numbers 0..255 or percentages), or 3 or 4 numbers: floats in 0..1, or integers in 0..255.- Returns:
ndarray, shape (3,) or (4,) – Floats in 0..1; the fourth entry, when present, is alpha.
- Raises:
ValueError – If the value is not a recognisable colour; the message names the value.
Examples
>>> from lcms2._parse import parse_color >>> parse_color("#ff8000").round(3) array([1. , 0.502, 0. ]) >>> parse_color("RebeccaPurple").round(3) array([0.4, 0.2, 0.6]) >>> parse_color("rgb(100%, 0%, 0%)") array([1., 0., 0.]) >>> parse_color((255, 0, 0)) array([1., 0., 0.])