向所有人致意!
我正在尝试阅读并将PDF文档的所有页面转换为jpeg。 到目前为止,它工作得很好,但是当我试图将一个想象实例克隆到另一个时,我已经碰到了头脑。
代码说的不仅仅是文字,所以:
$images = new Imagick();
$images->readimage($file['tmp_name']);
for($pageCounter = 0; $pageCounter < $images->getnumberimages(); $pageCounter++) {
$pagenumber = $pageCounter + 1;
$currentfilename = $filename . "_$pagenumber.jpg";
// iteration position
$images->setIteratorIndex($pageCounter);
$bigImage = new Imagick();
$thumbImage = new Imagick();
//I need to set the resolution to the original, that's why I need the
//$images variable. Is there another way to do it?
$bigImage->setresolution($images->getimagewidth(), $images->getimageheight());
$thumbImage->setresolution(240, 100);
//To avoid reading the same PDF-file twice (or three times in this case)
//i need to set the image of the new instances to the $images variable
//I figured that because the iterator has been set, I could just set the image
$bigImage->setimage($images);
$thumbImage->setimage($images);
$bigImage->scaleImage($images->getimagewidth(), $images->getimageheight());
$thumbImage->scaleimage(240, 0);
$bigImage->setImageFormat('jpeg');
$thumbImage->setimageformat('jpeg');
$bigImage->setImageBackgroundColor('white');
$thumbImage->setimagebackgroundcolor('white');
$bigImage->setImageCompressionQuality(100);
$thumbImage->setimagecompressionquality(100);
$bigImage = $bigImage->flattenimages();
$thumbImage = $thumbImage->flattenimages();
$bigImage->writeImage($bigPath . $currentfilename);
$thumbImage->writeImage($thumbPath . $currentfilename);
$bigImage->clear();
$thumbImage->clear();
$bigImage->destroy();
$thumbImage->destroy();
}
$images->clear();
$images->destroy();
$object->setPicture($thumbPath . $filename."_1.jpg");
我收到一条错误消息,说我正在尝试使用一个空的Imagick对象。
我也欢迎任何有关如何改进此代码的帮助;)