I do something similar, although I actually write the image to disk - When I used your direct output, it worked, and I got the actual color from the PDF.
After a bit of debugging, I realized that the problem was related to
imagick::resizeImage()
function. For some reason, when you set all your colors, compression, etc., ResizeImage adds a black background. My solution is to use GD to resize so that I have full dynamic size. Since you are not interested in this, I would simply use the image selection function. Your code should look like this:
<?php $file ="test.pdf"; $im = new imagick(realpath($file).'[0]'); $im->setCompression(Imagick::COMPRESSION_JPEG); $im->setCompressionQuality(80); $im->setImageFormat("jpeg"); $im->sampleImage(200,200);
source share