CFIMAGE CMYK Workaround To RGB
I deal with a large amount of CMYK
images from my clients. Some with color profiles and some without. So far Coldfusion
hasn’t been much help processing them. Although it gets closer with each new release. Here is my workaround to convert CMYK
images into RGB
until Adobe lets us convert images with the CFIMAGE
tag.
Starting Image
Above is the starting image of my faithful coding companion Bailey. I converted the image to CMYK
and added the U.S. Web Coated (SWOP) v2 color profile in Photoshop
.
When you try and read this image in Coldfusion 8/9
:
It throws the following error:
This is where Imagemagick
comes in. We can convert the image to RGB
and remove the color profiles so we can continue. I chose to use a BASH script that I call with CFEXECUTE
, but it appears to work calling it directly from CFEXECUTE
. I had problems in the past with this so I have always done it this way, in case you were wondering.
I pass this script the file I want to convert and where I want to create the new RGB version. The -strip command removes all the Photoshop meta data and the color profile. The -colorspace rgb
command converts the image from CMYK to RGB. Finally the -quality 100
sets the JPG quality setting for the new image, I created the original at 100 so I just kept it that way for the new one. (It can be adjusted to your personal preference or requirement from 1 to 100.) The new image will keep the same dimensions and resolution as the original image had to start.
Coldfusion Example:
In the Coldfusion
example I created here I first try to read the image information. If this fails I call the script to convert the image to RGB
and remove the profile information. Then I read the file with CFIMAGE
and it works. If that fails then you started out with a bum image to begin with.
If you aren’t on OS X or Linux and want to call ImageMagick directly it would work like this :
RGB File after Conversion
So here is the new image of Bailey converted to RGB
and all the profile information removed. The coloring of the image changes slightly when you convert it to RGB
from CMYK
, but so far I haven’t found a way to get it any closer. You can also resize and get the image info with Imagemagick
, but I am doing that with CFIMAGE
in hopes that I can one day just comment this out and all the operations will work consistently no matter the color format. Maybe Adobe will fix that in the next release so this can all be done in CFIMAGE
.
Hope this helps out others struggling with the same issue. This works well ( I have converted thousands of images) on Linux
and OSX
. I haven’t tried it on windows, but I would assume it would work by either calling it directly or wrapping it in a BATCH file. If anyone tries it on Microsft Windows let me know.
Links