php实现PDF转图片

安装Imagick扩展

https://pecl.php.net/package/imagick

tar -zxvf imagick-3.4.4.tgz
cd imagick-3.4.4
/www/server/php/71/bin/phpize 
./configure --with-php-config=/www/server/php/71/bin/php-config --with-imagick=/usr/local/imagemagick
make && make install


php.ini修改配置
[ImageMagick]
extension = "imagick.so"

重启fpm,查看配置,或phpinfo
php -m

 

实现PDF转PNG

function pdf2png()
{
  $pdf = '/www/wwwroot/sjyc/public/uploads/png/dhk.pdf';
  $path = '/www/wwwroot/sjyc/public/uploads/png/';

  if (!extension_loaded('imagick')) {
    echo 'no';exit;
  }

  if (!file_exists($pdf)) {
    echo 'no1';exit;
  }

  $im = new \Imagick();
  $im->setResolution(120, 120); //设置分辨率 值越大分辨率越高
  $im->setCompressionQuality(100);
  $im->readImage($pdf);
  foreach ($im as $k => $v) {
    $v->setImageFormat('png');
    $fileName = $path . md5($k . time()) . '.png';
    if ($v->writeImage($fileName) == true) {
      $return[] = $fileName;
    }
  }
  print_r($return);exit;
  return $return;
}

 

 

标记一下

安装img扩展

https://www.cnblogs.com/echo-php-study/p/12482263.html

代码实现

https://blog.csdn.net/jeff_love_marina/article/details/80838055