Transform Color Space

Description

Allows to transform the current object into a different color space, if possible.

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

hexcols.to(to, fixup=True)

Arguments

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

Examples

from colorspace import hexcols
x = hexcols(["#4B1D91", "#BF219A", "#F27B68", "#E7D39A"])
x
  • #4B1D91
  • #BF219A
  • #F27B68
  • #E7D39A
type(x)
colorspace.colorlib.hexcols
# Convert colors to sRGB
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
type(x)
colorspace.colorlib.sRGB
# Convert from sRGB to HCL
x.to("HCL")
x
polarLUV color object (4 colors)
            H       C       L
  1:   274.92   69.80   25.01
       326.40   90.46   44.94
        18.38   94.22   65.00
        69.59   45.16   84.95
# Convert back to hex colors.
# Round-off errors due to conversion to 'hex'.
x.to("hex")
x
  • #4B1D91
  • #BF219A
  • #F27B68
  • #E7D39A