Page 1 of 1

Can't convert PDF to JPG: Image width exceeds user limit in IHDR

Posted: 2017-03-10T11:13:07-07:00
by naoliv
While trying to convert this PDF file into a JPG image I am seeing a Image width exceeds user limit in IHDR error:

Code: Select all

$ convert -density 600 mapa_araraquara_atualizado_logradouros.pdf output.jpg 
convert-im6.q16: Image width exceeds user limit in IHDR `/tmp/magick-15788p2oGUMyrtVs31' @ warning/png.c/MagickPNGWarningHandler/1656.
convert-im6.q16: Image height exceeds user limit in IHDR `/tmp/magick-15788p2oGUMyrtVs31' @ warning/png.c/MagickPNGWarningHandler/1656.
convert-im6.q16: Invalid IHDR data `/tmp/magick-15788p2oGUMyrtVs31' @ error/png.c/MagickPNGErrorHandler/1630.
convert-im6.q16: corrupt image `/tmp/magick-15788p2oGUMyrtVs31' @ error/png.c/ReadPNGImage/3968.
convert-im6.q16: no images defined `output.jpg' @ error/convert.c/ConvertImageCommand/3258.
I need it in 600 dpi.
In gimp I can convert it up to 590 dpi.
In IM it fails even with 500.

What I think that is strange is that the error message comes from png.c, while I am trying to convert it to a JPEG file.
Does IM try to internally convert it to PNG first?

With 300 it also fails, but with another message:

Code: Select all

$ convert -density 300 mapa_araraquara_atualizado_logradouros.pdf saida.jpg 
convert-im6.q16: DistributedPixelCache '127.0.0.1' @ error/distribute-cache.c/ConnectPixelCacheServer/244.
convert-im6.q16: cache resources exhausted `/tmp/magick-15990uVPzMB2hDw4Z1' @ error/cache.c/OpenPixelCache/3945.
convert-im6.q16: no images defined `saida.jpg' @ error/convert.c/ConvertImageCommand/3258.
Version is:

Code: Select all

Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114 http://www.imagemagick.org
Copyright: © 1999-2017 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP 
Delegates (built-in): bzlib djvu fftw fontconfig freetype jbig jng jp2 jpeg lcms lqr ltdl lzma openexr pangocairo png tiff wmf x xml zlib
Any ideas about this, please?

Re: Can't convert PDF to JPG: Image width exceeds user limit in IHDR

Posted: 2017-03-10T11:39:00-07:00
by fmw42
Your image size is 2384x3370 at 72 dpi. If you want it at 600 dpi, then the dimensions will be width=2384*600/72=19867 and height=3372*600/72=28100. So the number of pixels = 558262700 = 558 Mpixels. So the color image before jpg compression will be 558 * 24-bits color = 13.392 Gbytes. Do you have enough ram to hold that size plus the compressed image before writing it out?

JPG files may also have a limited width or file size.

You may also be exceeding limits set in the IM policy.xml file.

Re: Can't convert PDF to JPG: Image width exceeds user limit in IHDR

Posted: 2017-03-10T11:42:23-07:00
by snibgo
Sorry, I can't currently download large files.

I suspect Ghostscript converts it to PNG, which IM reads in png.c.

I suspect Fred is correct, and the PNG that GS creates is too large for IM's memory.

Re: Can't convert PDF to JPG: Image width exceeds user limit in IHDR

Posted: 2017-03-10T11:46:35-07:00
by naoliv
I can use 20GB of RAM for this. I guess this should fit both compressed and uncompressed image?
Is there another way to convert it, please?

Re: Can't convert PDF to JPG: Image width exceeds user limit in IHDR

Posted: 2017-03-10T12:27:42-07:00
by fmw42
Ghostscript uses whatever sDEVICE is set in the delegates.xml. I think it is pngalpha. So yes it is likely going through png.

Re: Can't convert PDF to JPG: Image width exceeds user limit in IHDR

Posted: 2017-03-10T12:43:20-07:00
by snibgo
naoliv wrote:Is there another way to convert it, please?
GS can make JPEGs directly. See https://ghostscript.com/doc/9.20/Devices.htm#JFIF

Re: Can't convert PDF to JPG: Image width exceeds user limit in IHDR

Posted: 2017-03-10T12:48:45-07:00
by naoliv
Indeed. It did work.
Thank you very much!

Re: Can't convert PDF to JPG: Image width exceeds user limit in IHDR

Posted: 2017-03-10T14:43:33-07:00
by magick
Its likely the limit is imposed by the ImageMagick security policy, policy.xml. There may be a restrictive width or height setting preventing large images from being read or written by ImageMagick.