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

sRGB.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 sRGB
x = sRGB([0.294, 0.749, 0.949, 0.905],
         [0.113, 0.129, 0.482, 0.827],
         [0.568, 0.603, 0.407, 0.603])
x
sRGB color object (4 colors)
            R       G       B
  1:     0.29    0.11    0.57
         0.75    0.13    0.60
         0.95    0.48    0.41
         0.91    0.83    0.60
type(x)
colorspace.colorlib.sRGB
# Convert colors to CIEXYZ
x.to("CIELUV")
x
CIELUV color object (4 colors)
            L       U       V
  1:    24.96    6.02  -69.46
        44.92   75.45  -49.90
        64.98   89.52   29.78
        84.90   15.68   42.39
type(x)
colorspace.colorlib.CIELUV
# Convert from CIELUV to HCL
x.to("HCL")
x
polarLUV color object (4 colors)
            H       C       L
  1:   274.95   69.72   24.96
       326.52   90.46   44.92
        18.40   94.34   64.98
        69.70   45.20   84.90
# Convert back to Standard RGB colors.
x.to("sRGB")
x
sRGB color object (4 colors)
            R       G       B
  1:     0.29    0.11    0.57
         0.75    0.13    0.60
         0.95    0.48    0.41
         0.91    0.83    0.60
# Extracting hex colors (returns list of str)
x.colors()
['#4B1D91', '#BF219A', '#F27B68', '#E7D39A']