Transform Color Space

Description

Allows to transform the current object into a different color space, if possible. Converting the colors of the current object into another color space. After calling this method, the object will be of a different class.

Usage

RGB.to(to, fixup=True)

Arguments

tostr
Name of the color space into which the colors should be converted (e.g., "CIEXYZ", "HCL", "hex", "sRGB", …).
fixupbool
Whether or not colors outside the defined rgb color space should be corrected if necessary, defaults to True.

Examples

from colorspace import RGB
x = RGB([0.070, 0.520, 0.887, 0.799],
        [0.012, 0.015, 0.198, 0.651],
        [0.283, 0.323, 0.138, 0.323])
x
RGB color object (4 colors)
            R       G       B
  1:     0.07    0.01    0.28
         0.52    0.01    0.32
         0.89    0.20    0.14
         0.80    0.65    0.32
type(x)
colorspace.colorlib.RGB
# Convert colors to CIEXYZ
x.to("CIELUV")
x
CIELUV color object (4 colors)
            L       U       V
  1:    24.92    5.97  -69.56
        44.89   75.27  -50.15
        64.98   89.37   29.76
        84.94   15.78   42.32
type(x)
colorspace.colorlib.CIELUV
# Convert from CIELUV to HCL
x.to("HCL")
x
# Convert back to RGB
x.to("RGB")
x
RGB color object (4 colors)
            R       G       B
  1:     0.07    0.01    0.28
         0.52    0.02    0.32
         0.89    0.20    0.14
         0.80    0.65    0.32
# Extracting hex colors (returns list of str)
x.colors()
['#4B1D91', '#BF219A', '#F27B68', '#E7D39A']