1
votes

I have this bit that was setup years ago and has been working fine:

$imagick = new Imagick();
// Sets the image resolution
$imagick->setResolution(300, 300);
// Reads image from PDF
$imagick->readImage($pdf_here);
// apply CMYK profile before converting to RGB
$icc_cmyk = file_get_contents('../../profiles/CoatedGRACoL2006.icc');
$imagick->profileImage('icc', $icc_cmyk);
// convert to RGB using Adobe icc profile
$icc_rgb = file_get_contents('../../profiles/AdobeRGB1998.icc');
$imagick->profileImage('icc', $icc_rgb);
$imagick->setImageColorspace(Imagick::COLORSPACE_SRGB);
// crop to trim size
$imagick->cropImage(1050, 600, 37.5, 37.5);
// Writes an image
$imagick->writeImage($jpg_here);

But now today it's deciding it doesn't want to work anymore. I am generating a CMYK PDF that uses PMS colors that looks like this:

screenshot of PDF

And it's been converting fine, but now it's deciding to convert to this:

converted jpg

I have tried uploading different newer RGB and CMYK profiles with no luck, either it does nothing differently, or it inverts the colors. I am completely at a loss to what could have changed. I did not alter this file at all. I have been updating other aspects of the site that were coded about 10 years ago as MySQL queries, and needed to be updated to mySQLi with prepared statements.

1
Use -colorspace sRGB equivalent before reading the input. - fmw42
I tried it before setting the $icc_cmyk variable and it got locked up on the processing. - Alith7
Ghostscript does not read CMYK images properly. Using a profile before reading the image is not correct. It has to have something to work on and you have not read the input. But you can use -colorspace sRGB before reading the input. That tells ImageMagick and Ghostscript to convert the image to sRGB when reading the input. See php.net/manual/en/imagick.setcolorspace.php - fmw42
That did it. I had to change it from setImageColorSpace to setColorSpace. - Alith7

1 Answers

1
votes

As commented from @fmw42, the setImageColorspace wasn't working correctly. I ended up completely removing the profiles, and just using setColorspace. like this:

// create Imagick object
$imagick = new Imagick();
// Sets the image resolution
$imagick->setResolution(300, 300);
// set color space
$imagick->setColorspace(Imagick::COLORSPACE_SRGB);
// Reads image from PDF
$imagick->readImage($pdf_here);
// crop to trim size
$imagick->cropImage(1050, 600, 37.5, 37.5);
// Writes an image
$imagick->writeImage($jpg_here);