Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

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|improve this answer
    
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 :) –  kolypto Dec 25 '09 at 18:30
    
80Mb may be the default if you just add the -cache without a value following it. –  Shikoru Dec 25 '09 at 18:33
    
Hmm, my IMagick has only "-limit memory 64" to limit its memory to 64MB. It works, thanks anyway! :) –  kolypto Dec 25 '09 at 18:45
1  
Found: " -cache <threshold> (This option has been replaced by the -limit option)" –  kolypto Dec 25 '09 at 18:48
    
@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 –  thomasa88 Apr 28 '13 at 11:02

convert -limit memory 64 -limit map 128 original.djvu newfile.pdf

My main drive has limited space, so I prepend a variable

env MAGICK_TMPDIR=/host/Temp convert -limit memory 64 -limit map 128 original.djvu newfile.pdf

share|improve this answer
up vote 2 down vote accepted

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.