IIS:PHP Imagick(工作)与 Ghostscript(不工作)

IIS: PHP Imagick (working) with Ghostscript (not working)

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

这段代码:

$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 服务器上开箱即用。

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

Ghostscript Downloads

我确定我遗漏了一些非常重要的东西,所以现在我直接使用了 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);
    }
}