【问题标题】:IIS: PHP Imagick (working) with Ghostscript (not working)IIS:PHP Imagick(工作)与 Ghostscript(不工作)
【发布时间】:2021-05-01 08:01:16
【问题描述】:

我已经在 Windows Server 2016 Standard 上安装了 ImageMagick-7.0.10-Q16-HDRI 和 gs9.53.3。

这个sn-p:

$pages = [];
$im = new \Imagick();
$im->setresolution(150, 150);
$im->readimage("/test.pdf");
for ($i = 0; $i < $im->getnumberimages(); $i++) {
    $im->setiteratorindex($i);
    $im->setimageformat('jpg');
    $im->setImageAlphaChannel(\Imagick::ALPHACHANNEL_REMOVE);
    array_push($pages, addslashes($im->getimageblob()));
}
$im->destroy();

结果:

Fatal error: Uncaught ImagickException: PDFDelegateFailed `The system cannot find the file specified. ' @ error/pdf.c/ReadPDFImage/794 in .........\dev\gs_test.php:11 Stack trace: #0 E:\inetpub\wwwroot\test-analysis\dev\gs_test.php(11): Imagick->readimage() #1 {main} thrown in .......\dev\gs_test.php on line 11

我尝试将 gs4win64c.exe 复制到 gs.exe 并将C:\Program Files\gs\gs9.53.3\bin 添加到 PATH,现在得到:

Fatal error: Uncaught ImagickException: PDFDelegateFailed `Error: /undefinedfilename in (C:/Windows/TEMP/magick-8156OUt95Ei0WCah) Operand stack: Execution stack: %interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push Dictionary stack: --dict:737/1123(ro)(G)-- --dict:0/20(G)-- --dict:75/200(L)-- Current allocation mode is local Last OS error: Permission denied GPL Ghostscript 9.53.3: Unrecoverable error, exit code 1 ' @ error/pdf.c/ReadPDFImage/794 in .......\dev\gs_test.php:11 Stack trace: #0 ........\dev\gs_test.php(11): Imagick->readimage() #1 {main} thrown in .......\dev\gs_test.php on line 11

我对现在发生的事情有点困惑!完全相同的代码在我的测试 Unix 服务器上开箱即用。

【问题讨论】:

  • 我认为这可能是版本不兼容造成的。尝试更改 Ghostscript 的版本,将 Ghostscript 9.53.3 更改为 32 位。
  • 谢谢,但不幸的是我都安装了,我还尝试将 gs4win32c.exe 作为 gs.exe 放入,结果相同:)

标签: php windows iis ghostscript imagick


【解决方案1】:

Windows 和 Linux 下的许可证不同,请检查是否使用相同的 Ghostscript 源。因为你提到它在Unix服务器下可以正常工作。

Ghostscript Downloads

【讨论】:

  • 我肯定安装了 Windows 版本。这似乎是某种奇怪的权限问题——我尝试将 IIS_IUSRS、IUSR 和“IIS AppPool\Default Application Pool”(或其他任何内容)作为完全控制用户临时添加到 %TEMP%,但出现相同的错误.
【解决方案2】:

我已经确定我遗漏了一些非常重要的东西,所以现在我直接使用了 Ghostscript:

// Make sure gswin64c.exe is in %PATH%
// This is used with PHP upload

foreach ($_FILES as $f) {
    shell_exec("gswin64c.exe -sDEVICE=jpeg -sOutputFile={$f['tmp_name']}-page-%03d.jpg -r150x150 -f -dBATCH -dNOPAUSE -q {$f['tmp_name']}");
    $pages = [];
    foreach (glob("{$f['tmp_name']}-page-[0-9][0-9][0-9].jpg") as $page) {
        array_push($pages, addslashes(file_get_contents($page)));
        unlink($page);
    }
}

【讨论】:

    猜你喜欢
    • 2014-06-10
    • 2015-10-25
    • 2018-05-23
    • 2014-07-02
    • 2018-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-21
    相关资源
    最近更新 更多