Conversions Functions

Available functions:


RGB to HEX

Converts RGB to HEX

Parameters:
        r (int): Red value (0-255).
        g (int): Green value (0-255).
        b (int): Blue value (0-255).

Returns:
        str: A string representing the hex color code (e.g., "#FFFFFF").

HEX to RGB

Converts HEX to RGB

Parameters:
        hex_value (str): A string representing a hex color code (e.g., "#FFFFFF").

Returns:
        tuple: A tuple representing the RGB values (e.g., (255, 255, 255)).

RGB to HSL

Converts RGB to HSL.

Parameters:
        r (int): Red value (0-255).
        g (int): Green value (0-255).
        b (int): Blue value (0-255).

Returns:
        tuple: A tuple representing the HSL values (h, s, l) where
               h (float) is hue in the range [0, 360),
               s (float) is saturation in the range [0, 1],
               l (float) is lightness in the range [0, 1].

HSL to RGB

Converts HSL to RGB.

Parameters:
        h (float): Hue in the range [0, 360).
        s (float): Saturation in the range [0, 1].
        l (float): Lightness in the range [0, 1].

Returns:
        tuple: A tuple representing the RGB values (0-255).

RGB to HSV

Converts RGB to HSV.

Parameters:
        r (int): Red value (0-255).
        g (int): Green value (0-255).
        b (int): Blue value (0-255).

Returns:
        tuple: A tuple representing the HSV values (h, s, v) where
               h (float) is hue in the range [0, 360),
               s (float) is saturation in the range [0, 1],
               v (float) is value in the range [0, 1].

HSV to RGB

Converts HSV to RGB.

Parameters:
        h (float): Hue in the range [0, 360).
        s (float): Saturation in the range [0, 1].
        v (float): Value in the range [0, 1].

Returns:
        tuple: A tuple representing the RGB values (0-255).

RGB to CMYK

Converts RGB to CMYK.

Parameters:
        r (int): Red value (0-255).
        g (int): Green value (0-255).
        b (int): Blue value (0-255).

Returns:
        tuple: A tuple representing the CMYK values (c, m, y, k) where
               c (float) is cyan in the range [0, 1],
               m (float) is magenta in the range [0, 1],
               y (float) is yellow in the range [0, 1],
               k (float) is key/black in the range [0, 1].

CMYK to RGB

Converts CMYK to RGB.

Parameters:
        c (float): Cyan in the range [0, 1].
        m (float): Magenta in the range [0, 1].
        y (float): Yellow in the range [0, 1].
        k (float): Key/black in the range [0, 1].

Returns:
        tuple: A tuple representing the RGB values (0-255).

HEX to HSL

Converts HEX to HSL.

Parameters:
        hex_value (str): A string representing a hex color code (e.g., "#FFFFFF").

Returns:
        tuple: A tuple representing the HSL values (h, s, l) where
               h (float) is hue in the range [0, 360),
               s (float) is saturation in the range [0, 1],
               l (float) is lightness in the range [0, 1].

HEX to HSV

Converts HEX to HSV.

Parameters:
        hex_value (str): A string representing a hex color code (e.g., "#FFFFFF").

Returns:
        tuple: A tuple representing the HSV values (h, s, v) where
               h (float) is hue in the range [0, 360),
               s (float) is saturation in the range [0, 1],
               v (float) is value in the range [0, 1].

HEX to CMYK

Converts HEX to CMYK.

Parameters:
        hex_value (str): A string representing a hex color code (e.g., "#FFFFFF").

Returns:
        tuple: A tuple representing the CMYK values (c, m, y, k) where
               c (float) is cyan in the range [0, 1],
               m (float) is magenta in the range [0, 1],
               y (float) is yellow in the range [0, 1],
               k (float) is key/black in the range [0, 1].

HSL to HEX

Converts HSL to HEX.

Parameters:
        hsl_value (tuple): A tuple representing the HSL values (h, s, l) where
                           h (float) is hue in the range [0, 360),
                           s (float) is saturation in the range [0, 1],
                           l (float) is lightness in the range [0, 1].

Returns:
        str: A string representing the hex color code (e.g., "#FFFFFF").

Raises:
        ValueError: If the HSL values are out of range.

HSL to HSV

Converts HSL to HSV.

Parameters:
        hsl_value (tuple): A tuple representing the HSL values (h, s, l) where
                           h (float) is hue in the range [0, 360),
                           s (float) is saturation in the range [0, 1],
                           l (float) is lightness in the range [0, 1].

Returns:
        tuple: A tuple representing the HSV values (h, s, v) where
               h (float) is hue in the range [0, 360),
               s (float) is saturation in the range [0, 1],
               v (float) is value in the range [0, 1].

Raises:
        ValueError: If the HSL values are out of range.

HSL to CMYK

Converts HSL to CMYK.

Parameters:
        hsl_value (tuple): A tuple representing the HSL values (h, s, l) where
                           h (float) is hue in the range [0, 360),
                           s (float) is saturation in the range [0, 1],
                           l (float) is lightness in the range [0, 1].

Returns:
        tuple: A tuple representing the CMYK values (c, m, y, k) where
               c (float) is cyan in the range [0, 1],
               m (float) is magenta in the range [0, 1],
               y (float) is yellow in the range [0, 1],
               k (float) is key/black in the range [0, 1].

Raises:
        ValueError: If the HSL values are out of range.

HSV to HEX

Converts HSV to HEX.

Parameters:
        hsv_value (tuple): A tuple representing the HSV values (h, s, v) where
                           h (float) is hue in the range [0, 360),
                           s (float) is saturation in the range [0, 1],
                           v (float) is value in the range [0, 1].

Returns:
        str: A string representing the hex color code (e.g., "#FFFFFF").

Raises:
        ValueError: If the HSV values are out of range.

HSV to HSL

Converts HSV to HSL.

Parameters:
        hsv_value (tuple): A tuple representing the HSV values (h, s, v) where
                           h (float) is hue in the range [0, 360),
                           s (float) is saturation in the range [0, 1],
                           v (float) is value in the range [0, 1].

Returns:
        tuple: A tuple representing the HSL values (h, s, l) where
               h (float) is hue in the range [0, 360),
               s (float) is saturation in the range [0, 1],
               l (float) is lightness in the range [0, 1].

Raises:
        ValueError: If the HSV values are out of range.

HSV to CMYK

Converts HSV to CMYK.

Parameters:
        hsv_value (tuple): A tuple representing the HSV values (h, s, v) where
                           h (float) is hue in the range [0, 360),
                           s (float) is saturation in the range [0, 1],
                           v (float) is value in the range [0, 1].

Returns:
        tuple: A tuple representing the CMYK values (c, m, y, k) where
               c (float) is cyan in the range [0, 1],
               m (float) is magenta in the range [0, 1],
               y (float) is yellow in the range [0, 1],
               k (float) is key/black in the range [0, 1].

Raises:
        ValueError: If the HSV values are out of range.

CMYK to HSV

Converts CMYK to HSV.

Parameters:
        cmyk_value (tuple): A tuple representing the CMYK values (c, m, y, k) where
                            c (float) is cyan in the range [0, 1],
                            m (float) is magenta in the range [0, 1],
                            y (float) is yellow in the range [0, 1],
                            k (float) is key/black in the range [0, 1].

Returns:
        tuple: A tuple representing the HSV values (h, s, v) where
               h (float) is hue in the range [0, 360),
               s (float) is saturation in the range [0, 1],
               v (float) is value in the range [0, 1].

Raises:
        ValueError: If the CMYK values are out of range.

CMYK to HSL

Converts CMYK to HSL.

Parameters:
        cmyk_value (tuple): A tuple representing the CMYK values (c, m, y, k) where
                            c (float) is cyan in the range [0, 1],
                            m (float) is magenta in the range [0, 1],
                            y (float) is yellow in the range [0, 1],
                            k (float) is key/black in the range [0, 1].

Returns:
        tuple: A tuple representing the HSL values (h, s, l) where
               h (float) is hue in the range [0, 360),
               s (float) is saturation in the range [0, 1],
               l (float) is lightness in the range [0, 1].

Raises:
        ValueError: If the CMYK values are out of range.

CMYK to HEX

Converts CMYK to HEX.

Parameters:
        cmyk_value (tuple): A tuple representing the CMYK values (c, m, y, k) where
                            c (float) is cyan in the range [0, 1],
                            m (float) is magenta in the range [0, 1],
                            y (float) is yellow in the range [0, 1],
                            k (float) is key/black in the range [0, 1].

Returns:
        str: A string representing the hex color code (e.g., "#FFFFFF").

Raises:
        ValueError: If the CMYK values are out of range.

RGB to XYZ

Converts RGB to XYZ.

Parameters:
        r (int): Red component, in the range [0, 255].
        g (int): Green component, in the range [0, 255].
        b (int): Blue component, in the range [0, 255].

Returns:
        tuple: A tuple representing the XYZ values (x, y, z), where:
               x, y, z (float): Correspond to the CIE 1931 color space.

Raises:
        ValueError: If any RGB value is out of range.

XYZ to RGB

Converts XYZ to RGB.

Parameters:
        x (float): X component of the XYZ color space.
        y (float): Y component of the XYZ color space.
        z (float): Z component of the XYZ color space.

Returns:
        tuple: A tuple representing the RGB values (r, g, b), where:
               r, g, b (int): Red, Green, and Blue components, each in the range [0, 255].

Raises:
        ValueError: If any resulting RGB values are outside the valid range after conversion.

HEX to XYZ

Converts HEX to XYZ.

Parameters:
        hex_value (str): A hexadecimal color code (e.g., '#RRGGBB').

Returns:
        tuple: A tuple representing the XYZ values (x, y, z).

XYZ to HEX

Converts XYZ to HEX.

Parameters:
        xyz_value (tuple): A tuple of XYZ values (x, y, z).

Returns:
        str: A hexadecimal color code (e.g., '#RRGGBB').

HSL to XYZ

Converts HSL to XYZ.

Parameters:
        hsl_value (tuple): A tuple representing the HSL values (h, s, l).

Returns:
        tuple: A tuple representing the XYZ values (x, y, z).

XYZ to HSL

Converts XYZ to HSL.

Parameters:
        xyz_value (tuple): A tuple of XYZ values (x, y, z).

Returns:
        tuple: A tuple representing the HSL values (h, s, l).

HSV to XYZ

Converts HSV to XYZ.

Parameters:
        hsv_value (tuple): A tuple representing the HSV values (h, s, v).

Returns:
        tuple: A tuple representing the XYZ values (x, y, z).

XYZ to HSV

Converts XYZ to HSV.

Parameters:
        xyz_value (tuple): A tuple of XYZ values (x, y, z).

Returns:
        tuple: A tuple representing the HSV values (h, s, v).

CMYK to XYZ

Converts CMYK to XYZ.

Parameters:
        cmyk_value (tuple): A tuple of CMYK values (c, m, y, k).

Returns:
        tuple: A tuple representing the XYZ values (x, y, z).

XYZ to CMYK

Converts XYZ to CMYK.

Parameters:
        xyz_value (tuple): A tuple of XYZ values (x, y, z).

Returns:
        tuple: A tuple representing the CMYK values (c, m, y, k).

Blend colors

Blends two colors in the RGB format using the specified ratio.

Parameters:
        color1 (tuple): The first RGB color as a tuple of three integers (R, G, B).
        color2 (tuple): The second RGB color as a tuple of three integers (R, G, B).
        ratio (float, optional): The ratio to blend the colors. A value of 0.5 will
                                 blend both colors equally. Values closer to 0 will
                                 give more weight to `color1`, and values closer to
                                 1 will favor `color2`. Default is 0.5.

Returns:
        tuple: The blended color as an RGB tuple of three integers.

Example:
        >>> blend_colors((255, 0, 0), (0, 0, 255), 0.5)
        (127, 0, 127)

Last updated