PHP Ghostscript 错误,但命令行工作正常(将 pdf 解码为 png)


PHP Ghostscript error, but command line works fine (decoding pdf to png)

我正在从命令行执行此命令:

gs -sOutputFile=- -sDEVICE=pnggray -dFirstPage=1 -dLastPage=1 -dNOPAUSE -sPAPERSIZE=a4 -r90 -q /Volumes/DATA/03-www/temp/test.pdf -c quit

它工作正常,将pdf解码为png。但是然后我从php执行以下代码:

$cmd = "gs -sOutputFile=- -sDEVICE=pnggray -dFirstPage=1 -dLastPage=1 -dNOPAUSE -sPAPERSIZE=a4 -r90 -q " . $pdf_file . " -c quit";
$img = shell_exec($cmd);

我得到空响应。我将2>&1附加到$cmd以查看错误:

$cmd = "gs -sOutputFile=- -sDEVICE=pnggray -dFirstPage=1 -dLastPage=1 -dNOPAUSE -sPAPERSIZE=a4 -r90 -q " . $pdf_file . " -c quit 2>&1";

输出如下:

dyld: Library not loaded: /opt/local/lib/libtiff.5.dylib
  Referenced from: /opt/local/lib/libgs.9.16.dylib
  Reason: Incompatible library version: libgs.9.16.dylib requires version 8.0.0 or later, but libtiff.5.dylib provides version 6.0.0

Ghostscript 版本给出 (cli):

GPL Ghostscript 9.16 (2015-03-30)
Copyright (C) 2015 Artifex Software, Inc.  All rights reserved.

请帮忙吗?

在我看来

,您使用的是使用共享库的Ghostscript版本,并且系统找不到libtiff 8动态库。

您似乎安装了 libtiff 5,您需要 libtiff 8。据推测,libtiff 8 是为你的用户安装的,而不是 PHP 用户,这就是为什么它从命令行为你工作的原因。

或者您可以使用不使用共享库的

Ghostscript构建,但这意味着自己构建它,因为看起来您的发行版的打包程序已选择使用共享库。