Ross W
Ross W

Reputation: 11

Imagick resizeImage is not applying to multi page PDF's

I'm converting multi page PDF's to individual images, however only the last page in the PDF is being resized and compressed (line 5 onwards):

$image = new Imagick();
$image->setOption("pdf:use-trimbox","true");
$image->setResolution(300,300);
$image->readImage("test1.pdf");
$image->resizeImage(800,0,Imagick::FILTER_LANCZOS,1);
$image->setImageCompressionQuality(65);
$image->setImageFormat("jpeg");
$image->writeImages("name.jpeg",true);

I need to be able to output each PDF page as a single, resized and compressed image. If anybody could help, that would be great!

Upvotes: 1

Views: 576

Answers (1)

Danack
Danack

Reputation: 25721

The images are held as separate images internally in the Imagick object. To resize them all, you should call resize on them all:

foreach ($image as $subImage) {
    $subImage->resizeImage(800, 0, Imagick::FILTER_LANCZOS, 1);
}

Upvotes: 2

Related Questions