Command line CMYK <=> RGB works, Imagick does not.

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
NitroPye

Command line CMYK <=> RGB works, Imagick does not.

Post by NitroPye »

I am having some issues getting CMYK <=> RGB conversion working with Imagick. I am able to do this properly on the command line but when I do it thru Imagick I get improper colors.

Here is the convert command I use from the command line client:

Code: Select all

convert Test_CMYK.psd -profile ColorArt85290.icc -profile sRGB.icc -colorspace RGB Test_RGB.png
This works perfectly and colors are okay. But when I do this colors are messed up (as though I'm doing the CMYK conversion incorrectly)

Code: Select all

$img = new Imagick("File.psd");
$img->setImageFormat('jpeg');
$img->profileImage('ColorArt85290', 'ColorArt85290.icc');
$img->profileImage('sRGB', 'sRGB.icc');
$img->setImageColorspace(imagick::COLORSPACE_RGB);
header( "Content-Type: image/jpeg" );
echo $img;
Has anyone successfully used Imagick with CMYK images?
mkoppanen
Posts: 309
Joined: 2007-06-09T07:06:32-07:00

Re: Command line CMYK <=> RGB works, Imagick does not.

Post by mkoppanen »

On the first example you get png output and on the second one there is jpeg output. I don't know if that makes a difference. Can you post the images and profiles so that I can test?
Mikko Koppanen
My blog: http://valokuva.org
NitroPye

Re: Command line CMYK <=> RGB works, Imagick does not.

Post by NitroPye »

Using png for the Imagick example doesn't work either. I tried jpeg, because I wanted to set the image format to something that could handle CMYK in memory (to rule that out)

Here are the color profiles and example images I am using. I choose this example image because it has a ton of green making it very easy to tell when CMYK -> RGB goes wrong:

http://cole.nitroy.com/Files/Temp/IM_Test/
mkoppanen
Posts: 309
Joined: 2007-06-09T07:06:32-07:00

Re: Command line CMYK <=> RGB works, Imagick does not.

Post by mkoppanen »

using ImageMagick 6.4.0 03/31/08 Q16 http://www.imagemagick.org exactly the same results from command line and Imagick. The green colored image.
Mikko Koppanen
My blog: http://valokuva.org
NitroPye

Re: Command line CMYK <=> RGB works, Imagick does not.

Post by NitroPye »

Against the source image? On my end I get two different green images, one dark (correct), one very bright. I would love for this to be a simple goof up on my end as this is a problem I will eventually need to work around no matter what.

Here are the exact files I used: And to rule out any version discrepancies here are the versions I am running:

ImageMagick version

Code: Select all

coleman@babylon IM_Test $ convert --version
Version: ImageMagick 6.4.0 04/04/08 Q16 http://www.imagemagick.org
Imagick version

Code: Select all

imagick module version	2.1.1
NitroPye

Re: Command line CMYK <=> RGB works, Imagick does not.

Post by NitroPye »

*bump*

Anyone able to do a CMYK to RGB conversion with Imagick?
NitroPye

Re: Command line CMYK <=> RGB works, Imagick does not.

Post by NitroPye »

Many versions of ImageMagick and Imagick later I am still coming up against this issue.

Here is the exact code I am using with PHP:

Code: Select all

<?php
$img = new Imagick("Test_CMYK.psd");
$img->setImageFormat('png');
$icc = file_get_contents('ColorArt85290.icc');
$img->profileImage('ColorArt85290', $icc);
$icc = file_get_contents('sRGB.icc');
$img->profileImage('sRGB', $icc);
$img->setImageColorspace(imagick::COLORSPACE_RGB);
header( "Content-Type: image/png" );
echo $img;
?>
And here is the exact code I am using via the command line:

Code: Select all

convert Test_CMYK.psd -profile ColorArt85290.icc -profile sRGB.icc -colorspace RGB Test_RGB.png
The exact files I am using from ICC profiles to Image files are located here:
http://cole.nitroy.com/Files/Temp/Test_IM.zip

I even changed my delegates.xml file and altered all ghostscript delegates as mentioned in this article: http://john.ukmn.com/2007/06/19/imagema ... yk-to-rgb/

ImageMagick version 6.4.9-1
Imagick version 2.2.2RC4
Running on an Intel Mac as a 32bit binary on OS X 10.5.6 & 10.5.2

I have a feeling it has to do with the order of how I am doing things with Imagick in PHP that is the issue. The image created by the PHP Imagick is light washed out green while the original has dark deep greens. I've tried just about everything, has anyone at all been able to take a CYMK image in and spit out proper RGB out???
mkoppanen
Posts: 309
Joined: 2007-06-09T07:06:32-07:00

Re: Command line CMYK <=> RGB works, Imagick does not.

Post by mkoppanen »

Hello,

are you after this kind of output:

http://valokuva.org/~mikko/tests/Test_IM/test_out.png
Mikko Koppanen
My blog: http://valokuva.org
NitroPye

Re: Command line CMYK <=> RGB works, Imagick does not.

Post by NitroPye »

Yep thats exactly it!

Were you able to get that output via Imagick?
mkoppanen
Posts: 309
Joined: 2007-06-09T07:06:32-07:00

Re: Command line CMYK <=> RGB works, Imagick does not.

Post by mkoppanen »

NitroPye wrote:Yep thats exactly it!

Were you able to get that output via Imagick?
Yes, I was. Here is the script I used:

Code: Select all

<?php
$img = new Imagick("Test_CMYK.psd");

$icc = file_get_contents('sRGB.icc');
$img->profileImage('ICC', $icc);

$img->setImageColorspace(imagick::COLORSPACE_RGB);

$img->setImageFormat('png');
header( "Content-Type: image/png" );
echo $img;
I was able to reproduce the original problem you had with following convert command:

Code: Select all

convert Test_CMYK.psd -profile sRGB.icc -profile ColorArt85290.icc -colorspace RGB Test_RGB.png
Looks like the latter profile overrides the first one.
Mikko Koppanen
My blog: http://valokuva.org
NitroPye

Re: Command line CMYK <=> RGB works, Imagick does not.

Post by NitroPye »

Whooha! That was it!

I don't know how in all of my mucking about I didn't end up with using just the one profile.

Thanks a ton!

I owe you a pint!
Post Reply