April 10, 2021

[Note] convert, memory allocation failed, attempt to perform an operation not allowed

Trying to convert multiple image files to a PDF file:

$ convert *.gif output.pdf

Then I got bunch of errors such as:

convert-im6.q16: memory allocation failed `302.gif' @ error/gif.c/ReadGIFImage/1303.

This is due to insufficient memory, and can be fixed in ImageMagick policy file.

First, find where the policy file is by running this command:

$ identify -list policy | more

Mine is in /etc/ImageMatick-6/policy.xml

$ identify -list policy | more

Path: /etc/ImageMagick-6/policy.xml
  Policy: Resource
    name: disk
 

Edit the file and allocate more memory:

$ sudo vi /etc/ImageMagick-6/policy.xml

Find this line and change its value.  I have 64GB memory, allocated 32GB:

<policy domain="resource" name="memory" value="32GiB"/>


I ran, but encountered another error:

$ convert *.gif output.pdf
convert-im6.q16: attempt to perform an operation not allowed by the security policy `PDF' @ error/constitute.c/IsCoderAuthorized/408.

Again, this is due to the policy.  Edit the file again and remove or comment out these lines:

<!-- 
<policy domain="coder" rights="none" pattern="PS" />
<policy domain="coder" rights="none" pattern="PS2" />
<policy domain="coder" rights="none" pattern="PS3" />
<policy domain="coder" rights="none" pattern="EPS" />
<policy domain="coder" rights="none" pattern="PDF" />
<policy domain="coder" rights="none" pattern="XPS" />
-->

Then it worked fine.

 

Resources

 

No comments: