我经常使用 ImageMagickconvert
进行 *->PNG 转换,但当 PDF 超过 50 页时 —convert
会占用超过 3 Gib (!!!) 的内存。我猜它会先加载所有内容。
这太不可接受了。它应该逐页读取 PDF,为什么要一次读取全部内容呢?
也许有办法调整它?或者有什么好的替代方案?
答案1
已解决如下问题:
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
答案2
我正在使用以下内容:
convert -limit memory 64 -limit map 128 original.djvu newfile.pdf
我的主驱动器空间有限,因此我添加了一个变量
env MAGICK_TMPDIR=/host/Temp convert -limit memory 64 -limit map 128 original.djvu newfile.pdf
答案3
您尝试过缓存吗?
来自手册页
-缓存阈值
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.