Configuring memory allocation in ImageMagick

Ershad Kunnakkadan

By Ershad Kunnakkadan

on 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.

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

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
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.

Stay up to date with our blogs. Sign up for our newsletter.

We write about Ruby on Rails, ReactJS, React Native, remote work,open source, engineering & design.