[英]getting image dimensions in imagick
I'm trying to get the dimensions of images that i converted with imagick. 我正在尝试获取使用imagick转换的图像的尺寸。 This is my code: 这是我的代码:
$imagick = new \Imagick();
$imagick->setresolution(300,300);
$imagick->readimage($this->uploadPath . '/original/test.pdf');
$imagick->writeImages($this->uploadPath . "/large/preview-%d.jpg", false);
So i'm reading a multipage pdf file and i'm converting it to seperate jpg files. 因此,我正在读取多页pdf文件,并将其转换为单独的jpg文件。 What i want is to retrieve the jpg file dimensions from each image. 我想要的是从每个图像中检索jpg文件的尺寸。 Can i do this in an easy way? 我可以轻松地做到这一点吗? Or do i first need to write the images to the disc and then loop through each of them again? 还是我首先需要将映像写入光盘,然后再次遍历每个映像?
What about Imagick::getImageGeometry
? 那Imagick::getImageGeometry
呢? ( http://www.php.net/manual/en/imagick.getimagegeometry.php ) ( http://www.php.net/manual/zh/imagick.getimagegeometry.php )
In your case it should look something like this: 在您的情况下,它应如下所示:
$imagick = new \Imagick();
$imagick->setresolution(300,300);
$imagick->readimage($this->uploadPath . '/original/test.pdf');
$geometryInfo = $imagick->getImageGeometry();
// now $geometryInfo is an associative array with 'width' and 'height' items in it
$imagick->writeImages($this->uploadPath . "/large/preview-%d.jpg", false);
Update: 更新:
If you want to read concrete page from multipage PDF, try to use such trick: 如果要从多页PDF中读取具体页面,请尝试使用以下技巧:
$pageIndex = 0; // you can create "for/foreach" loop to go through all pages
$imagick->readimage($this->uploadPath . '/original/test.pdf[' . $pageIndex . ']');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.