ImageMagick's `convert` utility takes *too much* memory with PDF input

13,206

Solution 1

Solved with the following:

cat <<EOF > /etc/profile.d/ImageMagick.sh
# Set ImageMagick memory limits: it eats too much
export MAGICK_MEMORY_LIMIT=1024 # Use up to *MB of memory before doing mmap
export MAGICK_MAP_LIMIT=1024    # Use up to *MB mmaps before caching to disk
export MAGICK_AREA_LIMIT=4096   # Use up to *MB disk space before failure
export MAGICK_FILES_LIMIT=1024  # Don't open more than *file handles
EOF

Solution 2

Have you tried cache?

From the man page

-cache threshold

      megabytes of memory available to the pixel cache.

      Image pixels are stored in memory until 80 megabytes of
      memory have been consumed.  Subsequent pixel operations

      are cached on disk.  Operations to memory are  significantly 
      faster but if your computer does not have a sufficient 
      amount of free memory you may  want  to  adjust
      this threshold value.
Share:
13,206

Related videos on Youtube

streetlight
Author by

streetlight

Enthusiastic Python/JS back-end developer. Loves exceptional projects and challenging tasks. Architects chaos into well-structured formations. Friendly and business-minded. Loves people. Always smiles :) CV and Contacts

Updated on September 17, 2022

Comments

  • streetlight
    streetlight almost 2 years

    I often use ImageMagick's convert for *->PNG conversion, but when PDF has more than 50 pages — convert eats more that 3 Gib (!!!) of memory. I guess it first loads everything.

    That's unacceptable. It should read PDF page by page, why the heck all of them at once!

    Maybe there's a way to tune it somehow? Or any good alternatives?

  • streetlight
    streetlight over 14 years
    Is it an option for convert? I have only "-limit type value pixel cache resource limit". Plus your quote says "80Mb is the default", but my convert eats all RAM :)
  • Shikoru
    Shikoru over 14 years
    80Mb may be the default if you just add the -cache without a value following it.
  • streetlight
    streetlight over 14 years
    Hmm, my IMagick has only "-limit memory 64" to limit its memory to 64MB. It works, thanks anyway! :)
  • streetlight
    streetlight over 14 years
    Found: " -cache <threshold> (This option has been replaced by the -limit option)"
  • thomasa88
    thomasa88 about 11 years
    @kolypto In my interpretation, ImageMagick websites says that the default unit is bytes: "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)." imagemagick.org/script/command-line-options.php#limit