尝试运行命令
identify -list resource
查看您可以控制/限制的资源。它给出了这个:
Resource limits:
Width: 214.7MP
Height: 214.7MP
Area: 4.295GP
Memory: 2GiB <--- Default is 2 GiB
Map: 4GiB
Disk: unlimited
File: 1920
Thread: 1
Throttle: 0
Time: unlimited
然后你可以使用这样的命令来控制内存convert
and identify
and mogrify
identify -limit memory 1GiB -list resource
Resource limits:
Width: 214.7MP
Height: 214.7MP
Area: 4.295GP
Memory: 1GiB <--- 1 GiB for duration of this command
Map: 4GiB
Disk: unlimited
File: 1920
Thread: 1
Throttle: 0
Time: unlimited
因此,正如您在上面看到的,我将一个命令的内存限制为 1GB。
同样,您可以限制内存convert
with
convert -limit memory 1GiB -size ... file.png
您还可以在环境变量中一次性设置内存限制,如下所示:
MAGICK_MEMORY_LIMIT=30000 identify -list resource
Resource limits:
Width: 214.7MP
Height: 214.7MP
Area: 4.295GP
Memory: 29.3KiB
Map: 4GiB
Disk: unlimited
File: 1920
Thread: 1
Throttle: 0
Time: unlimited
或者在本次会议的其余部分中像这样:
export MAGICK_MEMORY_LIMIT=500000
identify -list resource
Resource limits:
Width: 214.7MP
Height: 214.7MP
Area: 4.295GP
Memory: 488KiB
Map: 4GiB
Disk: unlimited
File: 1920
Thread: 1
Throttle: 0
Time: unlimited
库尔特还提供了一些很好的建议here https://stackoverflow.com/a/27919679/2836621.