Page 1 of 1

Transform PDF to PNG (CMYK to RGB)

Posted: 2018-02-21T05:02:42-07:00
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 ! :)

Re: Transform PDF to PNG (CMYK to RGB)

Posted: 2018-02-21T05:13:39-07:00
by snibgo
You probably need to set the colorspace before reading the PDF, not after.

Re: Transform PDF to PNG (CMYK to RGB)

Posted: 2018-02-21T06:57:05-07:00
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');   

Re: Transform PDF to PNG (CMYK to RGB)

Posted: 2018-02-21T07:05:09-07:00
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.