ImageMagick 的 `convert` 实用程序在 PDF 输入中占用 *太多* 内存

kol*_*pto 12 memory convert imagemagick memory-usage

我经常使用 ImageMagickconvert进行 *->PNG 转换,但是当 PDF 超过 50 页时 -convert占用超过3 Gib (!!!) 的内存。我想它首先加载所有内容。

这是不可接受的。它应该一页一页地阅读PDF,为什么要一次全部阅读!

也许有办法以某种方式调整它?或者有什么好的替代品?

小智 11

我正在使用以下内容:

convert -limit memory 64 -limit map 128 original.djvu newfile.pdf
Run Code Online (Sandbox Code Playgroud)

我的主驱动器空间有限,所以我在前面添加了一个变量

env MAGICK_TMPDIR=/host/Temp convert -limit memory 64 -limit map 128 original.djvu newfile.pdf
Run Code Online (Sandbox Code Playgroud)


kol*_*pto 11

解决了以下问题:

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
Run Code Online (Sandbox Code Playgroud)


小智 9

你试过缓存吗?

从手册页

-缓存阈值

      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.
Run Code Online (Sandbox Code Playgroud)

  • 发现:“-cache &lt;threshold&gt;(此选项已被-limit选项替代)” (2认同)