12

ImageMagick is using huge amounts of memory to convert PDF files - more than 2GB. The command I'm using is:

convert -density 250 -resize 1280x myfile.pdf -interlace plane -strip -quality 40 -alpha flatten myfolder/myfile-%03d.jpg

How can this be improved? I have an 1GB limit or else the process is killed ruthlessly. ):

MaiaVictor
  • 51,090
  • 44
  • 144
  • 286

1 Answers1

19

Use the memory limit option.

Option usage shown here:

http://www.imagemagick.org/script/command-line-options.php#limit

-limit type value

Set the pixel cache resource limit.

Choose from: area, disk, file, map, memory, threads, or time.

The value for file is in number of files. The other limits are in bytes. Define arguments for the memory, map, area, and disk resource limits with SI prefixes (.e.g 100MB).

By default the limits are 768 files, 3GB of image area, 1.5GiB memory, 3GiB memory map, and 18.45EB of disk. These limits are adjusted relative to the available resources on your computer if this information is available. When any limit is reached, ImageMagick fails in some fashion but attempts to take compensating actions, if possible. For example, the following limits memory:

-limit memory 32MiB -limit map 64MiB

Andre Kampling
  • 5,476
  • 2
  • 20
  • 47
Randy Howard
  • 2,165
  • 16
  • 26
  • 2
    This does not work. I get a error pointing it couldn't allocate enough resources. – MaiaVictor Mar 13 '13 at 13:31
  • That's an example set of values from their command line option docs. You might need to use higher limits than that for your particular usage, quality settings, etc. For example, try something that will keep it under the 1GB limit you stated in your question originally. If it still needs more than that, you may have to lower the quality of the conversion to fit in the amount of RAM you can use in your process. – Randy Howard Mar 13 '13 at 13:35
  • 1
    This works for me. convert would be killed and I would experience intermittent freezes when calling `convert *.png out.pdf`. Intermittent freezes still occur, but less severe. In addition I set ` -limit thread 2` – Michael Franzl Apr 20 '14 at 17:18