0
votes

I am looking at the top comment on this page:

https://www.php.net/manual/en/imagick.setimagecolorspace.php

It has sample code for converting a CMYK image to RGB. However, there are two things I do not understand:

  1. It uses the profileImage function twice. Once to set the profile to CMYK if the image does not currently have a profile. The second use of the function adds the RGB profile to the image. Apparently, this means that the image now has at least two image profiles attached to it.

Question 1: Why would you want the image to have both a CMYK profile and an RGB profile? What exactly is being done here? How exactly does adding a second profile convert the image from CMYK to RGB?

  1. The very last line in the code is using the stripImage function which removes the profiles completely along with other things such as EXIF data.

Question 2: Why are we removing the profiles? Doesn't that undo everything that we just did?

1

1 Answers

0
votes

If the input image is CMYK and does not have a profile, then you can convert it two ways. The first is to simply use -colorspace sRGB. But that is not so accurate. A better way is to use two profiles. The first defines the input colorspace as CMYK and gives it a precise definition of its gamut and the second specifies it wants to convert to sRGB. There are a number of CMYK type profiles that can be used. Without more knowledge, I prefer USWebCoatedSWOP.icc. Likewise there are several sRGB profiles. See http://www.color.org/srgbprofiles.xalter and https://github.com/ellelstone/elles_icc_profiles/tree/master/profiles for profiles.