首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >IIS: PHP Imagick (使用)与Ghostscript (不使用)

IIS: PHP Imagick (使用)与Ghostscript (不使用)
EN

Stack Overflow用户
提问于 2021-01-27 21:14:27
回答 2查看 184关注 0票数 1

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

这段代码:

代码语言:javascript
运行
复制
$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();

结果如下:

代码语言:javascript
运行
复制
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,现在获取:

代码语言:javascript
运行
复制
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服务器上开箱即用。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-01-29 23:52:47

我认为我遗漏了一些非常重要的东西,所以现在我只是直接使用Ghostscript:

代码语言:javascript
运行
复制
// 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);
    }
}
票数 0
EN

Stack Overflow用户

发布于 2021-01-29 16:48:02

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

Ghostscript Downloads

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65919935

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档