Convert PDF to PNG fails with page number

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
timrprobocom
Posts: 1
Joined: 2018-12-03T17:10:23-07:00
Authentication code: 1152

Convert PDF to PNG fails with page number

Post by timrprobocom »

ImageMagick 6.8.9-9 with GhostScript 9.26 on Ubuntu 16.04.5 LTS

I have a web page that converts the first page of submitted PDFs to a PNG using

Code: Select all

convert -density 300 p241504.pdf[0] -flatten -resize 640x +repage p241504.png
This has worked for years. Starting yesterday, I'm now getting:

Code: Select all

convert: FailedToExecuteCommand `"gs" -q -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-27596PshlNjRKAVT4%d" "-f/tmp/magick-27596m331V1WQSJUK" "-f/tmp/magick-27596RgwLE5h5aFVq"' (-1) @ error/delegate.c/ExternalDelegateCommand/461.
convert: no images defined `p241504.png' @ error/convert.c/ConvertImageCommand/3210.
If I omit the page number [0] from convert, it works correctly, although it ends up with the last page, which I don't want. If I run the "gs" command by itself, without the -f parameters, it works correctly. I've temporarily changed to calling "gs" directly, but I'd rather use the single command line. Anything changed recently?

Tim Roberts
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert PDF to PNG fails with page number

Post by fmw42 »

Did your Linux distro change/update recently. The date of the ImageMagick version is more important than the version, since they often do not change the release number when they patch.

If that happened, then there may be a new security patch that includes a modified policy.xml file. See https://stackoverflow.com/questions/528 ... 3#52863413 and https://imagemagick.org/script/resources.php
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert PDF to PNG fails with page number

Post by snibgo »

The OP says "If I omit the page number [0] from convert, it works correctly, although it ends up with the last page, which I don't want." So it is reading the PDF, and "-flatten" overwrites all the pages with the last one. So it's not a security problem.
snibgo's IM pages: im.snibgo.com
zineer
Posts: 1
Joined: 2018-12-05T22:06:42-07:00
Authentication code: 1152

Re: Convert PDF to PNG fails with page number

Post by zineer »

I believe I'm hitting the same issue with a PDF to JPG conversion.

Code: Select all

$ convert '/tmp/test.pdf[0]'  '/tmp/test.jpg'
convert.im6: `%s' (%d) "gs" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -dFirstPage=1 -dLastPage=1 "-sOutputFile=/tmp/magick-n4Brt84N--0000001" "-f/tmp/magick-G9ikuZ1i" "-f/tmp/magick-jnvNyXYN" @ error/utility.c/SystemCommand/1890.
convert.im6: Postscript delegate failed `/tmp/test.pdf': No such file or directory @ error/pdf.c/ReadPDFImage/677.
convert.im6: no images defined `/tmp/test.jpg' @ error/convert.c/ConvertImageCommand/3044.
If I try without specifying the [0] it converts fine, creating a jpg for each of the 5 pages. I tried with the same PDF as I was last successful with (on November 21) and the same error occurs.

Looks like GhostScript was updated recently:

Code: Select all

$ convert -version
Version: ImageMagick 6.7.7-10 2018-09-28 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP

$ gs -version
GPL Ghostscript 9.26 (2018-11-20)
Copyright (C) 2018 Artifex Software, Inc.  All rights reserved.
wardrop
Posts: 5
Joined: 2014-02-09T17:10:27-07:00
Authentication code: 6789

Re: Convert PDF to PNG fails with page number

Post by wardrop »

I came to report the same issue.

I'm running OpenSUSE tumbleweed so using a very recent version of ImageMagick. `magick -version` reports "Version: ImageMagick 7.0.8-14 Q16 x86_64 20181023". GhostScript reports its version as "GPL Ghostscript 9.26 (2018-11-20)". The problem seems to be with PDF's containg PNG's with alpha channels. At least this is what I've found with my limited testing. The clue is in the error I suppose ('-sDEVICE=pngalpha'):

Code: Select all

magick: FailedToExecuteCommand `'gs' -sstdout=%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 '-sDEVICE=pngalpha' -dTextAlphaBits=4 -dGraphicsAlphaBits=4 '-r72x72' -dFirstPage=1 -dLastPage=1 '-sOutputFile=/tmp/magick-5294kpYdlcquZ3Hd%d' '-f/tmp/magick-529484XVb1u83srx' '-f/tmp/magick-5294n0dlV1Mxm7aR'' (-1) @ error/delegate.c/ExternalDelegateCommand/478.
Again I only get the issue if I specifiy the page with the square bracket syntax, e.g. magick /tmp/Untitled.pdf[0] /tmp/output.jpg. Doesn't seem to matter what the output format is.

Happy to supply a sample PDF if needed.
wardrop
Posts: 5
Joined: 2014-02-09T17:10:27-07:00
Authentication code: 6789

Re: Convert PDF to PNG fails with page number

Post by wardrop »

Dongrading to GhostScript 9.23 resolves the issue. Did this by installing the RPM package for OpenSUSE Leap 15 from here: http://download.opensuse.org/distributi ... ss/x86_64/

Not sure if this is a bug in Ghostscript, or just an compatibility issue between Ghostscript and ImageMagick?
GuillaumeV
Posts: 4
Joined: 2018-12-17T06:34:13-07:00
Authentication code: 1152

Re: Convert PDF to PNG fails with page number

Post by GuillaumeV »

wardrop wrote: 2018-12-10T23:03:46-07:00 Dongrading to GhostScript 9.23 resolves the issue. Did this by installing the RPM package for OpenSUSE Leap 15 from here: http://download.opensuse.org/distributi ... ss/x86_64/

Not sure if this is a bug in Ghostscript, or just an compatibility issue between Ghostscript and ImageMagick?
Hi ! I noticed the same bug on my side.
I am also in Ghostscript v9.26

After trying many documents to try to find what was causing this problem (It works for some documents).
In my case, the documents causing the error have a gradient color banner. I imagine it must be transparency the problem
GuillaumeV
Posts: 4
Joined: 2018-12-17T06:34:13-07:00
Authentication code: 1152

Re: Convert PDF to PNG fails with page number

Post by GuillaumeV »

Is there anything new on this issue?
This bug is critical for us as the default version of imagemagick in Debian Stretch (ImageMagick 6.9.7-4) still contains this bug whereas this issue is absent from Debian Jessie (ImageMagick 6.8.9-9).

Debian Buster (10) just came into Soft Freeze stage, after Full freeze it will be too late and this newly introduced bug will not be fixed for Debian Buster.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert PDF to PNG fails with page number

Post by fmw42 »

Have you tried downgrading from GS 9.26 to 9.23 or 9.24. I have heard of issues with 9.26.
zerocrates
Posts: 1
Joined: 2019-02-28T10:13:48-07:00
Authentication code: 1152

Re: Convert PDF to PNG fails with page number

Post by zerocrates »

It does seem to be a bug in 9.26:

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

There isn't yet a release containing the fix, though one should be coming in March judging by their usual schedule. I've had success applying the patch from the linked commit to the 9.26 source.
Post Reply