Reputation: 22480
This is the code I've got and it works fine. I just don't believe it is the "best" way to do it.
<?
$im = new imagick();
$im->setResolution(10,10);
$im->readimage('document.pdf');
$pages = $im->getNumberImages();
$im->clear();
$im->destroy();
for($i=0;$i<$pages;$i++) {
$im = new imagick();
$im->setResolution(100,100);
$im->readimage('document.pdf['.$i.']');
$im->setImageFormat('jpeg');
$im->writeImage($i.'.jpg');
$im->clear();
$im->destroy();
}
?>
Anyone knows how to do it the best way? Please show me how.
Upvotes: 1
Views: 1505
Reputation: 698
Hopefully this will help someone.
My solution is to use the method writeImages. Make sure you set the $adjoin flag to false to get seperate files.
$im = new imagick();
$im->setResolution(100,100);
$im->readimage('document.pdf');
$im->setImageFormat('jpeg');
$im->writeimages('document.jpg', false);
$im->clear();
$im->destroy();
It will result in document-0.jpg, document-1.jpg, document-3.jpg etc.
Upvotes: 2