【问题标题】:ghostscript 9.26 update breaks imagick readImage for multipage PDFghostscript 9.26 更新打破了多页 PDF 的 imagick readImage
【发布时间】:2019-05-02 19:10:58
【问题描述】:

自从昨天早上 ghostscript 更新 9.25 -> 9.26(在 debian 上)以来,我们收到了这个错误:

ErrorMessage: FailedToExecuteCommand 
`'gs' -sstdout=%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT
 -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 
'-sDEVICE=pngalpha' -dTextAlphaBits=4 -dGraphicsAlphaBits=4 '-r300x300' 
-dFirstPage=1 -dLastPage=1 '-sOutputFile=/tmp/magick-39903EapVvuyNQxL4%d' 
'-f/tmp/magick-39903VD0GMIpLPaIN' 
'-f/tmp/magick-399031owlSOb4aOEw'' (-1) 
@ error/delegate.c/ExternalDelegateCommand/462

尝试阅读多页 PDF 的第一页时:

$this->resource = new \Imagick();
$this->resource->setResolution(300, 300);
$this->resource->readImage($path . '[0]');

知道如何解决这个问题吗?

见:https://www.ghostscript.com/doc/9.26/History9.htm#Version9.26 见:https://secure.php.net/manual/en/imagick.readimage.php

【问题讨论】:

  • 顺便说一句。导致此更新出现问题的另一个错误是 Imagick scaleImage 重置了 setImageDepth 的值。因此,请务必在图像操作结束时设置深度。
  • 另一个问题中的这个答案对我有用,所以这个问题可以作为重复关闭并接受该答案:stackoverflow.com/a/54550273/4447371

标签: php ghostscript imagick


【解决方案1】:

几乎可以肯定这个错误报告:

https://bugs.ghostscript.com/show_bug.cgi?id=699815

您的解决方案是;不要使用 pngalpha 设备,不要使用 FirstPage/LastPage,升级到带有修复程序的版本,或者降级到早期版本。尽管该错误可能存在于许多早期版本中,但我不知道为什么以前没有出现过。

【讨论】:

  • 我在尝试通过 Ruby 的 MiniMagick gem 将 imagemagick 与 ghostscript 一起使用时遇到了这个问题。由于这不允许我控制发送到 imagemagick 的参数,我不得不将 ghostscript 降级到 9.25,从而解决了问题。
【解决方案2】:

我没有“解决方案”,但可以确认升级到 gs 9.26 后的问题。我发现,正如 KenS 指出的那样,在 gs 中删除参数 -dFirstPage=1 -dLastPage=1 时一切正常。

删除 gs 参数 -dMaxBitmap=500000000 也是可行的。在 PHP 中的含义,删除 [PAGE] 即:

$im = new \Imagick();
$im->readImage('/tmp/test.pdf');

我的工作解决方案是降级到 ghostscript 9.22。我正在使用 Ubuntu 仿生 LTS。因此我不得不跑:

sudo apt-get remove ghostscript
sudo apt-get autoremove
sudo apt-get install ghostscript=9.22~dfsg+1-0ubuntu1 libgs9=9.22~dfsg+1-0ubuntu1 libgs9-common=9.22~dfsg+1-0ubuntu1
sudo apt-mark auto libgs9
sudo apt-mark auto libgs9-common

【讨论】:

  • 我按照你的指示回到了 9.22,它可以工作了!谢谢。另外,究竟如何删除参数,如 dLast/FirstPage?
  • 使用 PHP 时(据我所知)无法更改后台使用的参数。我想“删除 dLast/FirstPage 参数”你只需要在没有 Pageinformation 的情况下调用 Imagick。 IE。 $im->readImage('/tmp/test.pdf');而不是 $im->readImage('/tmp/test.pdf[0]');
【解决方案3】:

(Ghostscript 9.26) 有同样的问题,增加 setResolution(600, 600) 后又开始工作了。

【讨论】:

    猜你喜欢
    • 2020-06-30
    • 2015-02-19
    • 2010-10-27
    • 2017-11-24
    • 2012-04-09
    • 1970-01-01
    • 2014-07-07
    • 1970-01-01
    • 2018-05-28
    相关资源
    最近更新 更多