Convert color values from RGB to CMYK with ICC profile
Posted: 2014-05-20T01:54:01-07:00
Hi everybody,
I've been working with Imagemagick for a while now (using it in a web project, thus using PHP to work with it), and I've ran into a problem. I hope a smart mind here can help me.
I have to implement a color picker in my project (again, web based), which is no hassle at all. Done that with some fancy vanilla css and javascript. But I also have to display the CMYK values of a color, which the user selects. And that is where my problem starts. All the rough calculations on the web convert from RGB to CMYK without respecting any ICC profile at all. So they come up with e.g. rgb(0,255,255) = cmyk(100,0,0,0). I need this conversion to be more accurate with respect to the gamut of a specific ICC profile (CoatedFogra39 to be precise). I have the profile, since it is openly available. But I do not know how to calculate single color values with respect to this profile (and then back to RGB with respect to AdobeRGB1998).
All that is necessary, in order to give the user visual feedback, like in Photoshop, when a selected RGB color is out of gamut of the active ICC profile, and give him the nearest suggested color which lies inside the given gamut. In the attached image you can see that 1) Photoshop converts rgb(0,255,255) to cmyk(84,0,21,0), which lies inside the gamut range of CoatedFogra39, and 2) suggests to change the color to the nearest rgb value inside the cmyk gamut, which corresponds to cmyk(84,0,21,0), thus, if one clicks on the suggested color, the rgb changes to rgb(86,169,198).
Is there a way I can achieve this sort of single color value calculation with Imagemagick?
I need to retrieve values as a string, array or whatever format, so I can return it to the script which displays the numbers in the color picker.
Thanks a huge-ton for reading my wall of text.
Tricon
I've been working with Imagemagick for a while now (using it in a web project, thus using PHP to work with it), and I've ran into a problem. I hope a smart mind here can help me.
I have to implement a color picker in my project (again, web based), which is no hassle at all. Done that with some fancy vanilla css and javascript. But I also have to display the CMYK values of a color, which the user selects. And that is where my problem starts. All the rough calculations on the web convert from RGB to CMYK without respecting any ICC profile at all. So they come up with e.g. rgb(0,255,255) = cmyk(100,0,0,0). I need this conversion to be more accurate with respect to the gamut of a specific ICC profile (CoatedFogra39 to be precise). I have the profile, since it is openly available. But I do not know how to calculate single color values with respect to this profile (and then back to RGB with respect to AdobeRGB1998).
All that is necessary, in order to give the user visual feedback, like in Photoshop, when a selected RGB color is out of gamut of the active ICC profile, and give him the nearest suggested color which lies inside the given gamut. In the attached image you can see that 1) Photoshop converts rgb(0,255,255) to cmyk(84,0,21,0), which lies inside the gamut range of CoatedFogra39, and 2) suggests to change the color to the nearest rgb value inside the cmyk gamut, which corresponds to cmyk(84,0,21,0), thus, if one clicks on the suggested color, the rgb changes to rgb(86,169,198).
Is there a way I can achieve this sort of single color value calculation with Imagemagick?
I need to retrieve values as a string, array or whatever format, so I can return it to the script which displays the numbers in the color picker.
Thanks a huge-ton for reading my wall of text.
Tricon