---
title: "Configuring memory allocation in ImageMagick"
description: "Configuring memory allocation in ImageMagick"
canonical_url: "https://www.bigbinary.com/blog/configuring-memory-allocation-in-imagemagick"
markdown_url: "https://www.bigbinary.com/blog/configuring-memory-allocation-in-imagemagick.md"
---

# Configuring memory allocation in ImageMagick

Configuring memory allocation in ImageMagick

- Author: Ershad Kunnakkadan
- Published: September 12, 2018
- Categories: Ruby

ImageMagick has a security policy file
[policy.xml](https://www.imagemagick.org/source/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.

```text

convert-im6.q16: DistributedPixelCache '127.0.0.1' @ error/distribute-cache.c/ConnectPixelCacheServer/244.
convert-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.

```text
$ identify -list policy

Path: /etc/ImageMagick-6/policy.xml
  Policy: Resource
    name: disk
    value: 1GiB
```

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

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

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

## Links

- [Human page](https://www.bigbinary.com/blog/configuring-memory-allocation-in-imagemagick)
