Configuring memory allocation in ImageMagick

Ershad Kunnakkadan

Ershad Kunnakkadan

September 12, 2018

ImageMagick has a security policy file policy.xml using which we can control and limit the execution of the program. For example, the default memory limit of ImageMagick-6 is 256 MiB.

Recently, we saw following error while processing a gif image.

1
2convert-im6.q16: DistributedPixelCache '127.0.0.1' @ error/distribute-cache.c/ConnectPixelCacheServer/244.
3convert-im6.q16: cache resources exhausted `file.gif' @ error/cache.c/OpenPixelCache/3945.
4

This happens when ImageMagick cannot allocate enough memory to process the image. This can be fixed by tweaking memory configuration in policy.xml.

Path of policy.xml can be located as follows.

1$ identify -list policy
2
3Path: /etc/ImageMagick-6/policy.xml
4  Policy: Resource
5    name: disk
6    value: 1GiB

Memory limit can be configured in the following line of policy.xml.

1<policy domain="resource" name="memory" value="256MiB"/>

Increasing this value would solve the error if you have a machine with larger a memory.

If this blog was helpful, check out our full blog archive.

Stay up to date with our blogs.

Subscribe to receive email notifications for new blog posts.