【问题标题】:Ghostscript over PHP on Mac Yosemite doesn't work. On Shell it worksMac Yosemite 上 PHP 上的 Ghostscript 不起作用。在壳牌上它工作
【发布时间】:2015-01-25 20:22:27
【问题描述】:

我很绝望……

我通过 Homebrew 在 Mac OS X Yosemite 上安装了 Ghostscript。 Ghostscript 在 shell 上运行良好,但如果通过 PHP 执行则无法运行。

$gs = '/usr/local/opt/ghostscript/bin/gs';

// Count PDF
$shell = $gs . ' -q    -dNODISPLAY    -c "(' . $pdf . ') (r) file runpdfbegin pdfpagecount = quit" 2>&1';
$result =  shell_exec($shell);

// Execution
$shell = $gs . ' -dNumRenderingThreads=4 -dNOPAUSE -sDEVICE=jpeg -dFirstPage=1 -dLastPage=1 -sOutputFile="' . $filePathThumb . '" -dJPEGQ=100 -r300 -q "' . $pdf . '" -c quit 2>&1';
$result =  shell_exec($shell);

$result 的输出是:

dyld: Library not loaded: /usr/local/lib/libtiff.5.dylib
Referenced from: /usr/local/opt/ghostscript/bin/gs
Reason: Incompatible library version: gs requires version 8.0.0 or later, but libtiff.5.dylib      provides version 7.0.0

如果我在 shell 上执行相同的命令,它就可以工作......

最近几天我累了很多东西,但我仍然在挣扎。

我重新安装了 gs 和 imagemagick,删除了符号链接,运行了 brew doctor,尝试了其他一些 libtiff.5.dyslib 文件。

我的环境:

  • 优胜美地
  • PHP 版本 5.5.13
  • Zend 服务器版本:7.0.0
  • Imagemagick 版本 6.8.9-8(通过 brew 安装)
  • Ghostscript 9.15 版(通过 brew 安装)

【问题讨论】:

    标签: php macos shell pdf ghostscript


    【解决方案1】:

    很明显,您正在使用带有共享库的 Ghostscript 版本(这就是它需要 libtiff.dylib 的原因)。我们不建议这样做,您可以通过下载 Ghostscript 源代码并自己构建它们来避免它。这是一个“需要一些程序集”的项目,因为您需要安装 gcc 之类的东西。但是我做到了,我离 Mac 专家还很远。

    但是,这可能只会让您了解真正的潜在问题,即您的 PHP 环境与您的 shell 不匹配。在这种情况下PATH环境变量可能不同,这意味着shell可以找到动态库,但PHP不能。

    由于 Ghostscript 可以使用某些环境变量,因此您需要确保 PHP 脚本执行的环境与 shell 使用的环境相同。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-03
    • 1970-01-01
    • 2023-04-06
    • 2016-04-06
    • 1970-01-01
    • 2018-08-11
    • 2015-02-22
    • 2014-12-20
    相关资源
    最近更新 更多