[英]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 下的 license 不同,請檢查是否使用相同的 Ghostscript 源。 因為您提到它在 Unix 服務器下正常工作。
我已經決定我錯過了一些非常重要的東西,所以現在我直接使用了 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);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.