shell_exec,imagemagick 将 pdf 转换为 jpg return 错误

shell_exec,imagemagick convert pdf to jpg return errors

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

我收到此错误:

Error: /undefined in findresource Operand stack: --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)-- Adobe-GB1 Execution stack: %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 Dictionary stack: --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)-- Current allocation mode is local Last OS error: 2

控制台命令正常

答案几乎肯定与 PATH 有关 - convertghostscriptPDF 方面需要)。

尝试以下不需要 ghostscript 的方法:

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

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

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

正如您在评论中所述,以下内容实际上解决了问题:

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