【问题标题】:How to convert pdf file to image using Imagick library in PHP?如何使用 PHP 中的 Imagick 库将 pdf 文件转换为图像?
【发布时间】:2017-01-22 23:04:56
【问题描述】:

我已经成功安装了 Imagick dll。我遵循了 stackoverflow 示例

How do I convert a PDF document to a preview image in PHP?

以下是我的代码

<?php
$im = new imagick('file.pdf[0]');
$im->setImageFormat('jpg');
header('Content-Type: image/jpeg');
echo $im;
?>

但我现在收到以下错误

Fatal error: Uncaught exception 'ImagickException' with message 'UnableToOpenBlob `demo.pdf': No such file or directory @ error/blob.c/OpenBlob/2657' in D:\xampp\htdocs\learn\index.php:2 Stack trace: #0 D:\xampp\htdocs\learn\index.php(2): Imagick->__construct('demo.pdf[0]') #1 {main} thrown in D:\xampp\htdocs\learn\index.php on line 2

Imagick dll 安装propelry

附上截图 请有人帮我解决这个问题?谢谢

【问题讨论】:

    标签: php codeigniter laravel image-processing


    【解决方案1】:
    public function pdfToJpg($param){
            $filename = $param['filename'];
            $image_name = $param['image_name'];
            $path = $param['path'];
            $db_path = $param['db_path'];
            $im = new Imagick();
            $im->setResolution(220,220);
            $im->readimage($filename."[0]");
            $im->setImageFormat('jpeg');
            $im->setImageBackgroundColor('#ffffff');
            $im->flattenImages();
            $image_name = $image_name.".jpg";//"save_as_name.jpg";
            $imageprops = $im->getImageGeometry();
            /*if ($imageprops['width'] <= 175 && $imageprops['height'] <= 300) {
             // don't upscale
             } else {
             $im->resizeImage(175,300, imagick::FILTER_LANCZOS, 0.9, true);
             }*/
    
            $im->writeImage($path.$image_name);
            if($im){
                $Img = array();
                $Img['status'] = 1;
                $Img['image'] = ($db_path.$image_name);
                return $Img;
            }
            $im->clear();
            $im->destroy();
        }
    

    试试看

    【讨论】:

      猜你喜欢
      • 2018-04-07
      • 2011-05-11
      • 1970-01-01
      • 2021-02-04
      • 1970-01-01
      • 1970-01-01
      • 2018-01-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多