Skip to content
Advertisement

Convert CMYK PDF to RGB JPG goes all black

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.

Advertisement

Answer

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);
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement