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

convertimagemagickmemorymemory usage

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?

Best Answer

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
Related Topic