Php Imagick和phmagick出现问题:Postscript委托失败/没有此类文件或目录
我正在使用imagick 3.0.1和phmagick(http://www.francodacosta.com/phMagick/download). 不管怎样,当我尝试将PDF转换为JPEG时,两者都会给我同样的错误 例如: Postscript委托失败“/tmp/magick-bfxIrUJ5”:没有这样的文件或目录@error/pdf.c/ReadPDFImage/669 我正在使用GhostScript-9.05(在/usr/local/bin/gs上运行)。 另外还有ImageMagick-6.7.6-8(在/usr/local/bin/convert上运行) 我已经检查了文件夹的权限(755)。ImageMagick在终端上的工作非常出色 例如,我的PHP使用Imagick:Php Imagick和phmagick出现问题:Postscript委托失败/没有此类文件或目录,php,pdf,imagemagick,ghostscript,imagick,Php,Pdf,Imagemagick,Ghostscript,Imagick,我正在使用imagick 3.0.1和phmagick(http://www.francodacosta.com/phMagick/download). 不管怎样,当我尝试将PDF转换为JPEG时,两者都会给我同样的错误 例如: Postscript委托失败“/tmp/magick-bfxIrUJ5”:没有这样的文件或目录@error/pdf.c/ReadPDFImage/669 我正在使用GhostScript-9.05(在/usr/local/bin/gs上运行)。 另外还有ImageMag
//use imagick
$im = new imagick( '/pdf/553571072.pdf' );
// convert to jpg
$im->setImageColorspace(255);
$im->setCompression(Imagick::COMPRESSION_JPEG);
$im->setImageFormat('jpeg');
//write image on server
$im->writeImage('/jpg/553571072.jpg');
顺便说一下,它出现在我的phpinfo()中。我正在linux/apache/amd64上工作
任何建议都将不胜感激 好的,多亏了努诺·弗朗哥·达科斯塔()的帮助,这终于奏效了 问题是我的GhostScript路径对于Shell来说是正确的,但是对于系统和PHP来说是错误的。要更正此错误,您应该将
/usr/local/bin/gs
文件链接到/usr/bin/gs
从Shell执行以下操作:
检查/usr/bin
中是否已存在gs
文件。如果有,我们将创建它的备份。如果没有
/usr/bin/gs
,您可以跳过此步骤
现在创建从/usr/local/bin/gs
到/usr/bin/gs
[root@din ~]# sudo ln -s /usr/local/bin/gs /usr/bin
这应该可以解决问题。非常感谢大家。我对@HelloWorld(谢谢!)提出的“纯PHP解决方案”的贡献在接受答案的评论中,有一点更正:必须在扩展默认路径之前添加变量名,因此putenv(getenv('PATH')。:/usr/local/bin')代码>不起作用,但
putenv('PATH='.getenv('PATH')。:/usr/local/bin')代码>将
*我的声誉不到50分,无法在正确的位置添加我的评论,因此我必须创建一个新的答案:-)我使用ImageMagickImageMagick 6.7.7-10
和GhostScript9.10
解决这些问题
事实证明PDF已损坏,尽管一些较新的GS版本可以读取它们,但鉴于以下错误,此旧版本无法读取
**** Warning: An error occurred while reading an XREF table.
**** The file has been damaged. This may have been caused
**** by a problem while converting or transfering the file.
**** Ghostscript will attempt to recover the data.
在Linux下,您可以先通过pdftk传递PDF:
pdftk 'bad.pdf' output 'fixed.pdf'
在那之后,我在Ubuntu上的一切都正常了。在终端上正常运行是无关紧要的。您没有在Apache的UID下运行,因此这不是有效的测试。您的代码示例是来自web应用程序还是来自命令行?你真的是从文件夹“/pdf”读到文件夹“/jpg”,也就是说,它们都在文件系统的根目录中吗?Halfer,代码来自web应用程序,我也尝试使用完整路径“/var/vhost/…../pdf/”,jpg也是如此。文件夹位于底部,与/css和/js相同。马克,我不明白你的意思,我正在VPS上运行一个web应用程序。谢谢大家。这也解决了我的问题。。。但是不可能指定php imagick gs可执行文件的位置吗?我刚刚给出了这个答案。有一个简单的解决办法。只需将“gs”的实际路径添加到php路径:putenv(getenv('path')。:/usr/local/bin')
**** Warning: An error occurred while reading an XREF table.
**** The file has been damaged. This may have been caused
**** by a problem while converting or transfering the file.
**** Ghostscript will attempt to recover the data.
pdftk 'bad.pdf' output 'fixed.pdf'