ColorAide

8.8.1 · active · verified Fri Apr 17

ColorAide is a comprehensive color library for Python, providing advanced color space conversions, manipulation, interpolation, and gamut mapping. It supports a wide range of color models and offers precise control over color operations. The library is actively maintained with frequent releases, currently at version 8.8.1.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates creating colors, converting between color spaces, mixing colors, checking gamut, and fitting colors to a target gamut using the `Color` class.

from coloraide import Color

# Create a color from a name or hex string
c = Color('red')
print(f"Initial color: {c.to_string()}")

# Convert to another color space and print
srgb_color = c.convert('srgb')
print(f"sRGB: {srgb_color.to_string(hex=True)}")

# Mix two colors
c1 = Color('blue')
c2 = Color('green')
mixed_color = c1.mix(c2, space='srgb', amount=0.5)
print(f"Mixed color: {mixed_color.to_string(hex=True)}")

# Check if a color is in gamut
p3_color = Color('color(--display-p3 0.9 0.1 0.5)')
print(f"Is P3 color in sRGB gamut? {p3_color.in_gamut('srgb')}")

# Fit a color to a gamut
out_of_gamut = Color('color(--rec2020 0.9 0.1 0.5)')
fit_srgb = out_of_gamut.fit('srgb')
print(f"Out of gamut: {out_of_gamut.to_string()}, Fit to sRGB: {fit_srgb.to_string()}")

view raw JSON →