I need to generate jpg images from PDF files (first page only). PDF files are created by the user, so they can contain anything. I am currently using the following code:
$i = new Imagick;
$i->setResolution(150, 150);
$i->loadImage("test.pdf[0]");
$i->thumbnailImage(640, 480, true);
$i->setImageBackgroundColor("white");
$i->setImageAlphaChannel(11);
$i->mergeImageLayers(Imagick::LAYERMETHOD_FLATTEN);
$i->writeImage("test.jpg");
This works as expected that transparency becomes white, not black. However, I ran into problems with some jpg images created, so I ran jpeginfoon them:
$ jpeginfo -c test.jpg
test.jpg 960 x 480 32bit JFIF N 9481 Unsupported color conversion request [ERROR]
It turns out that some of the original PDF files do use CMYK and apparently do not convert to RGB when saving as jpg. So I changed my code to the following (adding one line) to explicitly convert to RGB:
$i = new Imagick;
$i->setResolution(150, 150);
$i->loadImage("test.pdf[0]");
$i->thumbnailImage(640, 480, true);
$i->setImageBackgroundColor("white");
$i->setImageAlphaChannel(11);
$i->mergeImageLayers(Imagick::LAYERMETHOD_FLATTEN);
$i->setImageColorspace(Imagick::COLORSPACE_RGB);
$i->writeImage("test.jpg");
jpeg RGB, . - . : . Imagick , , , CMYK?