Transform PDF to PNG (CMYK to RGB)

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
r00t
Posts: 2
Joined: 2018-02-21T04:49:56-07:00
Authentication code: 1152

Transform PDF to PNG (CMYK to RGB)

Post by r00t »

Hi everyone !

I search on all the web with no results for this question.
I use imagick for transform the first index of a PDF to PNG.

This work very fine but there is difference (colors) between the first index and the PNG (see pics for example)

This image is the first index of the PDF (xxx.pdf)
Image

This image is the png generate by the first index (xxx.png)
Image

As you can see, the color is not the same...
This is my code :

Code: Select all

$im1 = new imagick($url);
$im1->setIteratorIndex(0);
$im1->setImageFormat('jpg');
// $im1->setImageColorSpace(Imagick::COLORSPACE_SRGB);
$im1->writeImage(ABSPATH.'medias/miniature-pdf/miniature-'.strtolower($filename).'-full.png');
(I already tried setImageColorSpace with no good result..)

Any ideas ?
Thanks ! :)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Transform PDF to PNG (CMYK to RGB)

Post by snibgo »

You probably need to set the colorspace before reading the PDF, not after.
snibgo's IM pages: im.snibgo.com
r00t
Posts: 2
Joined: 2018-02-21T04:49:56-07:00
Authentication code: 1152

Re: Transform PDF to PNG (CMYK to RGB)

Post by r00t »

Hi snibgo,

Thanks for your response.
What do you mean, when you say before reading the PDF ?

Something like this ?
(This doesn't work..)

Code: Select all

$im1 = new imagick();
$im1->setImageColorSpace(Imagick::COLORSPACE_SRGB);
$im1->readImage($url); 
$im1->setIteratorIndex(0);
$im1->setImageFormat('jpg');
$im1->writeImage(ABSPATH.'medias/miniature-pdf/miniature-'.strtolower($filename).'-full.png');   
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Transform PDF to PNG (CMYK to RGB)

Post by snibgo »

Yes, that's what I mean. The reason is that rasterizing the PDF is done (by the delegate, Ghostscript) when the PDF is read. If your PDF contains a profile, the conversion to sRGB should be done by using the "-profile" mechanism. I don't use IMagick so can't test this.
snibgo's IM pages: im.snibgo.com
Post Reply