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

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
naoliv
Posts: 110
Joined: 2007-12-10T18:54:27-07:00
Location: Brazil

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

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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.
snibgo's IM pages: im.snibgo.com
naoliv
Posts: 110
Joined: 2007-12-10T18:54:27-07:00
Location: Brazil

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

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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
snibgo's IM pages: im.snibgo.com
naoliv
Posts: 110
Joined: 2007-12-10T18:54:27-07:00
Location: Brazil

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

Post by naoliv »

Indeed. It did work.
Thank you very much!
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

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

Post 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.
Post Reply