cmyk-conversions-php-function

Convert Between RGB and CMYK Color Values with PHP

The CMYK color model is a subtractive color model used in color press printing. CMYK refers to the four inks used in some color printing: cyan, magenta, yellow, and key (black). In additive color models such as RGB (used in computer monitors, for example), white is the “additive” combination of all primary colored lights, while black is the absence of light. In the CMYK model, it is the opposite: inked (white) paper absorbs or reflects specific wavelengths, so cyan, magenta and yellow pigments serve as filters, subtracting varying degrees of red, green and blue from white light to produce a selective gamut of spectral colors (the CMYK color model is called subtractive because inks “subtract” brightness from white).

To save money on ink, and to produce deeper black tones, unsaturated and dark colors are produced by using black ink instead of the combination of cyan, magenta and yellow. The actual printing is made up of low(ish) resolution dots in a way that forces our brain to fill in the gaps and see an image. With this means of rendering images, photographers often whinge and whine about the way their photos are represented in print media because of the way in which CMYK printing deflates their vibrant colors… so it’s not a perfect model, but it works well for general printing purposes.

Image: When CMY “primaries” are combined at full strength, the resulting “secondary” mixtures are red, green, and blue. Mixing all three gives black.

Read more about CMYK on Wikipedia .

The RGB model can represent every colour that CMYK can represent; but the converse is not true. Without tapping into ImageMagik or something similar, the values returned by a PHP function are “close” at best. The functions on this page will do an okay job of converting between RGB and CMYK values. If you come across a more effective means, please let me know.

RGB to CMYK

CMYK to RGB

The function will return either a formatted string (alter the function format parameter as required) or as an array.

Download the PHP Code

Download the functions and examples from this page here .

Shortt URL for this post:

Leave a Reply

Your email address will not be published. Required fields are marked *