.png to .pdf conversion is failing with memory allocation error.

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
RAmbika
Posts: 10
Joined: 2018-03-27T06:45:41-07:00
Authentication code: 1152

.png to .pdf conversion is failing with memory allocation error.

Post by RAmbika »

Hi Team,

When we try to convert a particular .png file of size 35MB is giving the below error:

convert.exe: memory allocation failed `001_25.png[0]' @ error/cache.c/AcquireCacheNexusPixels/4983.
Caught exception: Magick: Strip/tile too large for JPEG. `JPEGPreEncode' @ error

We are using the convert.exe command like this:
convert.exe 001_25.png -resize ! -density "200" result.pdf

ImageMagick version we are using : 7.0.8.12

Please find the input image file at the below path.

https://drive.google.com/file/d/12jsITN ... sp=sharing

Could you please let us know how can we resolve this issue?

Thanks,
Ambika
(case - 25048669)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: .png to .pdf conversion is failing with memory allocation error.

Post by snibgo »

Your "-resize !" is not documented syntax. What do you want IM to do with it?

For v7, I suggest you use "magick", not "convert" or "magick convert".

Your input is large, 315 M pixels.

For me, IM v7.0.7.-28 on a Windows 12 GB laptop, the command ...

Code: Select all

magick 001_25.png -density 200 x.pdf
... works fine, using a 2.5 GB temporary file for the pixel cache because I don't have enough free memory. But Adobe Acrobat Reader says:
The dimensions of this page are out-of-range. Page content might be truncated.
Check your temporary area (/tmp on Unix or %TEMP% on Windows) has enough free space.

You might try limiting memory usage so the pixel cache is forced to disk:

Code: Select all

magick 001_25.png -limit memory 10MB -limit map 10MB x.pdf
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: .png to .pdf conversion is failing with memory allocation error.

Post by fmw42 »

-resize needs a new size value. You cannot just use ! by itself. See https://imagemagick.org/script/command- ... p#geometry
RAmbika
Posts: 10
Joined: 2018-03-27T06:45:41-07:00
Authentication code: 1152

Re: .png to .pdf conversion is failing with memory allocation error.

Post by RAmbika »

Hi,

We tried on the Windows 16 GB machine by freeing up the temporary area with the suggested commands:
1. magick 001_25.png -density 200 x.pdf
2. magick 001_25.png -limit memory 10MB -limit map 10MB x.pdf

There is 10 GB free memory but, still we get the same error(magick: memory allocation failed `001_25.png[0]' @ error/cache.c/AcquireCacheNexusPixels/4983).

Thanks,
Ambika
RAmbika
Posts: 10
Joined: 2018-03-27T06:45:41-07:00
Authentication code: 1152

Re: .png to .pdf conversion is failing with memory allocation error.

Post by RAmbika »

Hi,

Could you please help us to resolve this issue?

Thanks,
Ambika
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: .png to .pdf conversion is failing with memory allocation error.

Post by magick »

The conversion worked for us without complaint. We're using the latest ImageMagick release, 7.0.8-62. Download this release and let us know if the problem persists.
RAmbika
Posts: 10
Joined: 2018-03-27T06:45:41-07:00
Authentication code: 1152

Re: .png to .pdf conversion is failing with memory allocation error.

Post by RAmbika »

Hi,

If I directly install the ImageMagick exe(ImageMagick-7.0.8-62-Q8-x86-dll.exe) and try the conversion it is working fine.
But, by following the steps mentioned here https://imagemagick.org/script/install- ... hp#windows to extract the binaries and then if we try the conversion using the generated exe, then the conversion is not working.

could you please help us to resolve this issue in this scenario?

thanks,
Ambika
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: .png to .pdf conversion is failing with memory allocation error.

Post by snibgo »

RAmbika wrote:...then the conversion is not working.
Have you checked the build with simpler commands like "magick rose: r.png"?
What happens with your command? Any error messages? What is the text output if you insert "-verbose" as the first option?
snibgo's IM pages: im.snibgo.com
RAmbika
Posts: 10
Joined: 2018-03-27T06:45:41-07:00
Authentication code: 1152

Re: .png to .pdf conversion is failing with memory allocation error.

Post by RAmbika »

Hi,

The command "magick rose: r.png" works fine with the build.

With command "magick 001_25.png -density 200 x.pdf" it is throwing the error "magick: memory allocation failed `001_25.png[0]' @ error/cache.c/AcquireCacheNexusPixels/4987)."

By inserting "-verbose" as first option in our command like "magick -verbose 001_25.png -density 200 x.pdf" we get the following:
001_25.png PNG 3392x93021 3392x93021+0+0 8-bit Gray 256c 35.3529MiB 33.166u 0:34.402
001_25.png=>x.pdf PNG 3392x93021 3392x93021+0+0 8-bit Grayscale Gray 256c 35.3529MiB 31.122u 0:31.155
magick: pixel cache allocation failed `001_25.png[0]' @ error/cache.c/AcquireCacheNexusPixels/4987.

Please have a look into this and let us know the way to get the successful conversion.

Thanks,
Ambika
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: .png to .pdf conversion is failing with memory allocation error.

Post by snibgo »

Sorry, I don't know what else to suggest.
snibgo's IM pages: im.snibgo.com
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: .png to .pdf conversion is failing with memory allocation error.

Post by magick »

Try this command:

Code: Select all

magick -limit memory 1GiB -limit map 2GiB -define registry:temporary-path=./ 001_25.png -density 200 x.pdf
Does that command work for you?
RAmbika
Posts: 10
Joined: 2018-03-27T06:45:41-07:00
Authentication code: 1152

Re: .png to .pdf conversion is failing with memory allocation error.

Post by RAmbika »

Code: Select all

magick -limit memory 1GiB -limit map 2GiB -define registry:temporary-path=./ 001_25.png -density 200 x.pdf
this command did not work for us


It looks like regression issue. It worked for us with the 6.9.1-2 version of ImageMagick.
After upgrading to 7.0.7.21 and later this particular .png file works no more for us with 32-bit binaries.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: .png to .pdf conversion is failing with memory allocation error.

Post by magick »

The command works flawlessly for us. We're using ImageMagick 7.0.8-64, the latest release under Linux. We'll try under Windows when we get a chance.
RAmbika
Posts: 10
Joined: 2018-03-27T06:45:41-07:00
Authentication code: 1152

Re: .png to .pdf conversion is failing with memory allocation error.

Post by RAmbika »

Did you get a chance to check under windows environment?
Post Reply