Error “convert: cache resources exhausted” (SOLVED)
March 22, 2022
When using the convert utility to convert images, you may encounter an error stating that the cache resources have been exhausted.
Command example:
convert -density 300 -quality 100 input.pdf output.png
An example of the error it causes:
convert-im6.q16: cache resources exhausted `/tmp/magick-q7O_IcbbGpFULs5R34rLlwAyeW1slGHi19' @ error/cache.c/OpenPixelCache/4095.
This error occurs when two conditions are combined:
- processing a large file (for example, when converting PDF to JPG)
- weak computer with little RAM
As a quick fix, you can try reducing the image quality:
convert -density 150 -quality 70 input.pdf output.png
The -density option specifies the horizontal and vertical density of the image, that is, the number of dots. Typically, for scanning photographs, the setting is set to 300 dots – this is enough for good image quality for viewing on a monitor screen and for printing. You can experiment by choosing a lower value.
The -quality option specifies the compression level for JPEG/MIFF/PNG. Option value 100 means no compression, 100% image quality. An option value of 70 means 70% of the image quality by reducing its size.
If you do not want to reduce the quality, then you can try changing the settings. To do this, open the policy.xml file. Depending on your Linux distribution and version of ImageMagick, the path to the file may vary, for example:
- /etc/ImageMagick-6/policy.xml
- /etc/ImageMagick-7/policy.xml
Find and edit the string value:
<policy domain="resource" name="memory" value="256MiB"/>
Related articles:
- Error “attempt to perform an operation not allowed by the security policy `PDF'” (SOLVED) (100%)
- How to convert PDF to JPG using command line in Linux (SOLVED) (68.7%)
- How to convert JPG to PDF (68.7%)
- What program to open .docbook files (DocBook) (62.3%)
- Error “convert: delegate failed `'potrace' --svg --output '%o' '%i'' @ error/delegate.c/InvokeDelegate/1911” (SOLVED) (57%)
- How to find rows with empty column value in MySQL/MariaDB table (in phpMyAdmin and in command line) (RANDOM - 50%)
Thank you for this tip. It's a good idea in this day and age where every PC has many GB of RAM and cameras are writing larger and larger files to increase this value.
Increasing this value to 1024 GiB is a practical value.
You have 1024 Gb of RAM?
Thank you. It solved my problem.
I resolved this error by changing the file at: #/etc/imagemagick-6/policy.xml
I reset all "policy ... resource" lines with larger values.