繁体   English   中英

使用imagemagick将pdf文件转换为图像

[英]convert pdf files to image using imagemagick

我已经从网上安装了imageMagick和ghostscript并将其放到Mamp中,但是我没有得到如何将它们包括在我的php代码中..通过谷歌搜索我找到了一个代码

<?php
    $pdf = 'serviceReport.pdf';
    $save = 'output.jpg';

    exec('convert "'.$pdf.'" -colorspace RGB -resize 800 "'.$save.'"', $output, $return_var);

?>

但我没有得到结果..任何人都可以帮忙

使用ImageMagick提供的php扩展名(Imagick)代替命令行工具非常有效:

<?php
// ...
$img = new \Imagick();
$img->readimage($filedata['tmp_name']); // this can be a pdf file!
$img->setResolution(300,300);
$img->writeImage(sprintf('%1$s/%2$s.jpg', $basepath, $basename));
// ...
?>

另一种选择是改为使用poppler工具。 它们提供了更快的处理速度。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM