ImageMagick / Imagick使用本机PHP API将PDF转换为JPG [英] ImageMagick/Imagick convert PDF to JPG using native PHP API

查看:460
本文介绍了ImageMagick / Imagick使用本机PHP API将PDF转换为JPG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将PDF文件转换为PNG。它在命令行中运行良好(我安装了GhostScript 8.64)。但是从PHP我遇到了问题:

I’m attempting to convert PDF files into PNGs. It works great from the command line (I do have GhostScript 8.64 installed). But from PHP I’m having a problem:

代码:

$im = new Imagick($pdf_file); // this is where it throws the exception below

输出:

Fatal error: Uncaught exception ‘ImagickException’ with message ‘Postscript delegate failed `23_1235606503.pdf’: No such file or directory @ pdf.c/ReadPDFImage/612′ in get_thumbnail.php:93
Stack trace:
\#0 get_thumbnail.php(93): Imagick->__construct(’…’)

等。等等。

我不确定我在这里做错了什么,但我怀疑它与某处的服务器配置有关。我正在运行:
Apache 2.2.11
PHP 5.2.8
ImageMagick 6.4.8-9
GhostScript 8.64

I'm not sure what I'm doing wrong here, but I suspect it has something to do with my server configuration somewhere. I'm running: Apache 2.2.11 PHP 5.2.8 ImageMagick 6.4.8-9 GhostScript 8.64

推荐答案

最后想出来了。 GhostScript可执行文件( gs )不在Apache的环境路径中。它在 / usr / local / bin 中。虽然我尝试了几种方法将 / usr / local / bin 添加到路径中,但我没有成功。我最终在 / usr / bin目录中为 gs 添加了一个符号链接。现在一切都很完美。

Finally figured this out. The GhostScript executable (gs) wasn't in Apache's environment path. It was in /usr/local/bin. Though I tried several ways to add /usr/local/bin to the path, I did not succeed. I ended up putting a symlink for gs in the /usr/bin directory. Now everything works perfectly.

这篇关于ImageMagick / Imagick使用本机PHP API将PDF转换为JPG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆