CentOS下安装pdf转图片的imagick扩展,附示例
作者:互联网
- sudo yum -y install ImageMagick
- sudo yum -y install ImageMagick-devel
- sudo yum -y install ghostscript
- sudo wget http://pecl.php.net/get/imagick-3.4.3.tgz
- sudo pecl install imagick-3.4.3.tgz #imagick-3.4.3.tgz是下载后的压缩包
- 在php.ini添加 extension=imagick.so
关键代码示例:
public function convert($pdfFilePath)
{
$imgExt = '.png';
$Imagick = new \Imagick();
$Imagick->setResolution(120,120);
$Imagick->setCompressionQuality(100);
$Imagick->readImage($pdfFilePath);
$imgUrls = [];
foreach ($Imagick as $Key => $image){
$image->setImageFormat('png');
$imgFilePath = $this->pdfImgFilesDir.'/'.$this->genFilename().$imgExt;
if($image->writeImage($imgFilePath) == true){
$imgUrls[] = $this->uploadToAliyunAndReturnUrl($imgFilePath, $imgExt);
// 上传后删除
@unlink($imgFilePath);
}
}
return $imgUrls;
}
标签:imgExt,imgFilePath,CentOS,示例,image,Imagick,imagick,install 来源: https://blog.csdn.net/patriot_28/article/details/113919180