系统相关
首页 > 系统相关> > CentOS下安装pdf转图片的imagick扩展,附示例

CentOS下安装pdf转图片的imagick扩展,附示例

作者:互联网

  1. sudo yum -y install ImageMagick
  2. sudo yum -y install ImageMagick-devel
  3. sudo yum -y install ghostscript
  4. sudo wget http://pecl.php.net/get/imagick-3.4.3.tgz
  5. sudo pecl install imagick-3.4.3.tgz #imagick-3.4.3.tgz是下载后的压缩包
  6. 在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