conversions.rgb_cmyk_conversion

Functions

rgb_to_cmyk(→ tuple[int, int, int, int])

Simple RGB to CMYK conversion. Returns percentages of CMYK paint.

Module Contents

conversions.rgb_cmyk_conversion.rgb_to_cmyk(r_input: int, g_input: int, b_input: int) tuple[int, int, int, int]

Simple RGB to CMYK conversion. Returns percentages of CMYK paint. https://www.programmingalgorithms.com/algorithm/rgb-to-cmyk/

Note: this is a very popular algorithm that converts colors linearly and gives only approximate results. Actual preparation for printing requires advanced color conversion considering the color profiles and parameters of the target device.

>>> rgb_to_cmyk(255, 200, "a")
Traceback (most recent call last):
    ...
ValueError: Expected int, found (<class 'int'>, <class 'int'>, <class 'str'>)
>>> rgb_to_cmyk(255, 255, 999)
Traceback (most recent call last):
    ...
ValueError: Expected int of the range 0..255
>>> rgb_to_cmyk(255, 255, 255)  # white
(0, 0, 0, 0)
>>> rgb_to_cmyk(128, 128, 128)  # gray
(0, 0, 0, 50)
>>> rgb_to_cmyk(0, 0, 0)    # black
(0, 0, 0, 100)
>>> rgb_to_cmyk(255, 0, 0)  # red
(0, 100, 100, 0)
>>> rgb_to_cmyk(0, 255, 0)  # green
(100, 0, 100, 0)
>>> rgb_to_cmyk(0, 0, 255)    # blue
(100, 100, 0, 0)