Home Blog Convert Between RGB and CMYK Color Values with PHP

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.

Convert Between RGB and CMYK Color Values with PHP

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.



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


All the examples on this page have omitted the pre tags for formatting purposes. The download includes working code. We have a number of color posts scheduled (and published) that’ll work with color data in various ways; they will all be available via the color Tag: color tag.


Title: Convert RGB and CMYK Color Values
Description: Convert Between RGB and CMYK Color Values with PHP
Download: PHP Code (V0.2) | Plugin Page

Shortt URL for this post: http://shor.tt/1XN1


Please enter your comment!
Please enter your name here