【问题标题】:shell_exec,imagemagick convert pdf to jpg return errorsshell_exec,imagemagick 将 pdf 转换为 jpg 返回错误
【发布时间】:2017-03-02 00:22:59
【问题描述】:

我使用 imagemagick 将 PDF 文件转换为 JPG ,使用 PHP shell_exec('convert ./a.pdf ./a.jpg')

我得到这个错误:

错误:/undefined in findresource 操作数堆栈:--dict:15/24(L)-​​- F3 16.0 --dict:6/6(L)-- --dict:6/6(L)-- DroidSansFallback-UniGB-UTF16-H --dict:10/12(ro)(G)-- --nostringval -- CIDFontObject --dict:7/7(L)-- --dict:7/7(L)-- Adob​​e-GB1 执行栈: %interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval -- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1862 1 3 %oparray_pop 1861 1 3 %oparray_pop 1845 1 3 %oparray_pop --nostringval-- --nostringval-- 2 1 1 --nostringval-- %for_pos_int_continue --nostringval-- --nostringval-- --nostringval-- --nostringval-- %array_continue --nostringval-- false 1 %stopped_push --nostringval-- %loop_continue --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- nostringval-- %array_continue --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- %loop_continue 字典栈:--dict:1154/1684(ro)(G)-- --dict:1/20(G)-- --dict:75/200( L)-- --dict:75/200(L)-- --dict:106/127(ro)(G)-- --dict:286/300(ro)(G)-- --dict: 22/25(L)-- --dict:4/6(L)-- --dict:26/40(L)-- 当前分配模式是本地 最后操作系统错误:2

控制台中的命令没问题。

【问题讨论】:

  • 答案几乎肯定与 PATH 相关——convertghostscript。尝试将a.jpg 转换为b.jpg。如果这样可行,则指向ghostscript 的路径是错误的。如果它不起作用,则它是convert 的路径,或者脚本没有在您认为的文件夹中执行。
  • @MarkSetchell hi MarkSetchell。我解决了问题,我添加了代码putenv("PATH=/usr/local/bin");。正常工作。谢谢
  • 太好了,我已将其扩展并作为完整答案供所有人查看 - 请考虑通过单击投票计数旁边的空心勾号/复选标记来接受它作为答案。祝你的项目好运!
  • @MarkSetchell OK

标签: php imagemagick shell-exec


【解决方案1】:

答案几乎肯定与PATH 相关——convertghostscript(这是PDF 方面所必需的)。

试试下面的,不需要ghostscript

shell_exec('convert a.jp b.jpg');

如果可行,那是 PATHghostscript 是错误的。

如果它不起作用,则是 PATHconvert 错误,或者脚本没有在您认为的文件夹中执行。

正如您在 cmets 中所说,以下实际上解决了问题:

putenv("PATH=/usr/local/bin");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-01
    • 2015-10-23
    • 2011-09-29
    • 2018-04-26
    • 2022-11-04
    相关资源
    最近更新 更多