奇怪的问题——PHP / ImageMagick / Ghostscript

发布于 2024-07-26 12:17:13 字数 1240 浏览 0 评论 0原文

这个问题很接近,但是没有成功。 我正在尝试将 pdf 转换为 jpg(用于缩略图)。 这是我正在运行的命令:

convert -quality 100 -density 200x200 /path/file.pdf /path/file.jpg

我已经正确安装并运行了 mamp pro 1.7.2、imagemagick、ghostscript。 该命令在 shell 中完美运行,但在 php 脚本中运行时失败。 另一个变化是,对于图像到图像的转换,shell 和脚本都可以完美地工作。 这会让我相信 apache/php 环境中存在一些与 Ghostscript (gs) 相关的路径问题,尽管 gs 二进制文件与转换二进制文件位于同一目录中。 另外,我还根据 brybot.ca 的优秀教程 - www.brybot.ca/archives/getting-imagemagick-and-more-to-work-with-mamp-on-os-x 调整了 mamp apache envars /)所以 ImageMagick 工作得很好并且“/opt/local/bin”在我的 apache 路径变量中。

通过 shell,从 pdf 到图像的转换需要一些时间,我有一个挥之不去的想法,即 php 脚本在 imagemagick / Ghostscript 转换完成之前终止/完成,并可能中止 imagemagick 转换过程......? 我尝试过 exec、system、shell_exec 均无济于事。

我没有从命令中得到任何输出,似乎什么也没有发生,apache 或 php 日志中也没有显示任何内容。

更新:现在重新启动 MAMP 后,我在 apache 日志中收到以下错误

convert: unable to create temporary file `/path/file.pdf': Permission denied @ pdf.c/ReadPDFImage/358. convert: missing an image filename `/path/file.jpg' @ convert.c/ConvertImageCommand/2766.

有人有任何想法吗? 我正在为此抓狂......

非常感谢!

This question was close, but doesn't do the trick. I am trying to convert a pdf into a jpg (for thumbnailing). Here is the command I am running:

convert -quality 100 -density 200x200 /path/file.pdf /path/file.jpg

I have mamp pro 1.7.2,imagemagick, ghostscript all properly installed and working. This command works perfectly from a shell but fails when being run from within a php script. Another twist, is for an image to image conversion, things work perfectly from both shell and script. That would lead me to believe there is some path issue relating to ghostscript (gs) from within the apache/php environment although the gs binary is sitting in the same directory as the convert binary. Also, I had tweaked the mamp apache envars per (brybot.ca's excellent tutorial -- www.brybot.ca/archives/getting-imagemagick-and-more-to-work-with-mamp-on-os-x/) so ImageMagick is working great AND "/opt/local/bin" is in my apache path variable.

Via a shell, the conversion from pdf to image takes a few moments and I have a nagging thought that the php script is terminating/finishing before the imagemagick / ghostscript conversion is complete and possibly aborting the imagemagick conversion process...? I have tried exec, system, shell_exec all to no avail.

I get no output from the command nothing seems to happen and nothing showing up in apache or php logs.

UPDATE: Now I'm getting the following error in apache log after restarting MAMP

convert: unable to create temporary file `/path/file.pdf': Permission denied @ pdf.c/ReadPDFImage/358. convert: missing an image filename `/path/file.jpg' @ convert.c/ConvertImageCommand/2766.

Anyone have any ideas? I'm pulling my hair out on this...

Thanks so much!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我是男神闪亮亮 2024-08-02 12:17:13

Apache 通常在您的服务器上具有有限的权限(这就是您希望的方式),尝试将文件放入您知道 apache 具有写入权限的 /tmp 中。 Apache 也可能在读取其他用户创建的文件时遇到问题,除非它们是世界可读的。

Apache usually has limited permissions on your server (and that's how you want it to be), try putting the files into /tmp where you know apache has write permissions. Apache might also have trouble reading files that were created by other users, unless they are world-readable.

梦回旧景 2024-08-02 12:17:13

我读过一些文章,最好使用 exec 使用 shell 命令,更好的方法是使用 php 中内置的 Imagick。 欲了解更多信息,请阅读链接

谢谢
有梦想的一天

I read out some article the is not best to use shell command using exec,better way to use the inbuilt Imagick in php. for more you read out to Link

Thanks
have Dream Day

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文