Converting single RGB color value to CMYK with ICC profiles

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
lehik
Posts: 2
Joined: 2016-01-14T07:34:08-07:00
Authentication code: 1151

Converting single RGB color value to CMYK with ICC profiles

Post by lehik »

I'm sure this has been asked before, but I couldn't find a solution from earlier threads, so here goes: I'm developing a PHP application that deals with color values incoming in RGB and the app should convert them to CMYK. The PHP runs ImageMagick convert command with exec() -function. I've used ImageMagick for some basic image crop/resize -stuff, but I feel that my understanding is a bit lacking here...

For example, let's say that I have RGB color #dfd3c1 which equals 223,211,193. Based on what I found from other threads, I managed to build something like this:

convert xc:"rgb(223,211,193)" -profile sRGB.icc -profile ISOnewspaper26v4.icc -format "%[fx:int(100*c)], %[fx:int(100*m)], %[fx:int(100*y)], %[fx:int(100*k)]\r\n":

The output in percentages should be something like 3,6,16,14, but I'm getting 0.894179%, 5.71908%, 13.8964%, 2.82902%

The questions:
1) What's wrong with the command? Why the values aren't what they _should_ be?
2) In PHP, how can I just "echo" out the value to store the output from the exec to an variable? I managed to make the convert command to write the output to a file, but it would be much easier to have it output as string which I could store to a variable.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Converting single RGB color value to CMYK with ICC profiles

Post by snibgo »

You need "info:" at the end. That's probably just a copy-paste typo.

I get slightly different values to you.

Code: Select all

convert xc:"rgb(223,211,193)" -profile sRGB.icc -profile ISOnewspaper26v4.icc -format "%[fx:(100*r)], %[fx:(100*g)], %[fx:(100*b)], %[fx:(100*k)]\r\n" info:

0.968948, 6.12955, 13.9956, 2.80156
Perhaps this is a different version of the ICC.

A plain CMYK conversion, without prfiles, is:

Code: Select all

convert xc:"rgb(223,211,193)" -colorspace CMYK -format "%[fx:(100*r)], %[fx:(100*g)], %[fx:(100*b)], %[fx:(100*k)]\r\n" info:

0, 5.38186, 13.4524, 12.549
This is more or less the same, but with a greater K value.
lehik wrote:The output in percentages should be something like 3,6,16,14
Where did those numbers come from?

I don't know PHP, sorry. I think you can send stdout to an array, one (string) element per line of text.
snibgo's IM pages: im.snibgo.com
lehik
Posts: 2
Joined: 2016-01-14T07:34:08-07:00
Authentication code: 1151

Re: Converting single RGB color value to CMYK with ICC profiles

Post by lehik »

Thanks a lot for such a quick reply!

The missing "info" on my example was indeed a copy-paste error. Also, I managed to get the output to PHP as desired.

The plain conversion works as expected, but when I try to use profiles, I get just 0,0,0,0 so there is something fishy going on. Maybe the path to the profile is not correct, I'll have to double check that one.

In my previous message, the numbers 3,6,16,14 were supposed to be CMYK percent values, sorry for causing confusion by leaving the % sign out. I got the values from a graphic designer who said that those should be the CMYK values for RGB 223,211,193 when using the profiles.
Post Reply