What is the best way to correct black background when converting multi page PDF to JPG with Imagick php extension?
Following is the code used on my application:
$imagick = new Imagick($file);
$imagick->setResolution(150,150);
$imagick->setImageFormat("jpg");
$imagick->setImageCompression(imagick::COMPRESSION_JPEG);
$imagick->setImageCompressionQuality(70);
foreach ($imagick as $c => $_page) {
$_page->setImageBackgroundColor('white');
$_page->adaptiveResizeImage($maxsize,$maxsize,true);
$_page->writeImage("$file-$c.jpg");
}
I'am aware that the flattenImage method can be used to remove black background, such as in:
$imagick = $imagick->flattenImages();
But when the file has more the one pages, the flattenImages method puts all the pages on the same image, and therefore the result is a copy of the last page in all the JPGs generated.
I appreciate if anybody can help me.