93

I'm using Imagemagick on a rails app with Minimagick and I generate some pictogram with it.

When I launch my process I have this error and I don't find a solution:

MiniMagick::Error (`convert -limit memory 2GiB -limit map 2GiB -limit   disk 4GiB -background none -fill #000000 -font ttf/SELIS006N.ttf -pointsize 300 label: S public/pictogram_images/RECINTAN-EL-064-layer-1.png` failed with error:
convert.im6: cache resources exhausted ` S' @ error/cache.c/OpenPixelCache/4078.
convert.im6: no images defined `public/pictogram_images/RECINTAN-EL-064-layer-1.png' @ error/convert.c/ConvertImageCommand/3044.
):

My process is simple, I have some .tff file and each character is a pictogram. I just want to generate all preview of this character in png.

Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33
Gregory Frerot
  • 1,141
  • 1
  • 8
  • 12

4 Answers4

151

Find the policy.xml with find / -name "policy.xml"

something like /etc/ImageMagick-6/policy.xml

and change

<policy domain="resource" name="disk" value="1GiB"/>

to

<policy domain="resource" name="disk" value="8GiB"/>

refer to convert fails due to resource limits

Memory issues

Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33
LF00
  • 27,015
  • 29
  • 156
  • 295
  • 1
    I also had to define `` in order for my error message `convert-im6.q16: cache resources exhausted 'myimage.jpg' @ error/cache.c/OpenPixelCache/3945.` to disappear. – Anthony O. Jan 16 '19 at 22:10
  • For more details see the solution discussed here: https://github.com/ImageMagick/ImageMagick/issues/396#issuecomment-326849298 – RHertel Apr 21 '19 at 18:26
  • 1
    this worked, created mirror note explaining this https://blog.eq8.eu/til/imagemagic-cache-resources-exhausted.html – equivalent8 Nov 26 '20 at 14:11
  • It's possible to comment all lines policy limits in order to have unlimited resources. To comment the policy lines, just wrap the doing – R. W. Prado Feb 14 '22 at 03:38
  • 1
    @R.W.Prado It's not proposed to set unlimited resource here. But you can try it and check it with `identify -list resource` to see if it works. – LF00 Feb 14 '22 at 05:49
40

The error probably occurs because you run out of memory. You can check for the resources using the following command:

convert -list resource

The output will be somewhat like this:

Resource limits:
  Width: 16KP   
  Height: 16KP   
  Area: 128MP   
  Memory: 256MiB   
  Map: 512MiB   
  Disk: 1GiB   
  File: 768   
  Thread: 8   
  Throttle: 0   
  Time: unlimited

Here, you can see that the assigned amounts of disk space and memory are very small. So, in order to modify it you need to change the policy.xml file located somewhere in /etc/ImageMagick-6 directory.
Change <policy domain="resource" name="disk" value="1GiB"/> to <policy domain="resource" name="disk" value="4GiB"/> in the policy.xml file.

Teee
  • 994
  • 1
  • 11
  • 22
Yogita Bhatia
  • 541
  • 4
  • 7
6
sed -i '/disable ghostscript format types/,+6d' /etc/ImageMagick-6/policy.xml //this one is just to solve convertion from .tiff to pdf, you may need it some day
sed -i -E 's/name="memory" value=".+"/name="memory" value="8GiB"/g' /etc/ImageMagick-6/policy.xml
sed -i -E 's/name="map" value=".+"/name="map" value="8GiB"/g' /etc/ImageMagick-6/policy.xml
sed -i -E 's/name="area" value=".+"/name="area" value="8GiB"/g' /etc/ImageMagick-6/policy.xml
sed -i -E 's/name="disk" value=".+"/name="disk" value="8GiB"/g' /etc/ImageMagick-6/policy.xml
John Balvin Arias
  • 2,632
  • 3
  • 26
  • 41
-1

Not sure exactly which item is causing you the problem, but it is probably one of these:

1) You need to put your font into ImageMagick's XML-based font file rather than specify a file.ttf in your convert command. To get the list of available fonts, use

identify -list font | more

Path: /Users/mark/.magick/type.xml          <--- Edit your font into here
  Font: ACaslonPro
    family: unknown
    style: Undefined
    stretch: Undefined
    weight: 0
    glyphs: /Library/Fonts/ACaslonPro-Regular.otf
  Font: ACaslonPro-Semibold
    family: unknown
    style: Undefined
    stretch: Undefined
    weight: 0
    glyphs: /Library/Fonts/ACaslonPro-Semibold.otf
...
...

At the beginning you will see the path to the config file for your fonts and you need to edit that to include your TTF file you mentioned. If you have lots of fonts to add, you may like to automate the process - see my other post here.

2) You may need to escape the # in your -fill option, or at least surround it by single, or double quotes to hide it from the shell, if your MiniMagick invokes via shell - I don't know the ins and outs of MiniMagick.

3) You may need to quote the letter S that you wish to output inside single or double quotes.

4) You may need to remove the space after the colon following label.

What I am getting at is that your command should maybe be more like this:

convert -limit memory 2GiB -limit map 2GiB -limit   disk 4GiB -background none -fill "#000000" -font "TimesNewRoman" -pointsize 300 label:"S" output.png
Community
  • 1
  • 1
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • I do not see any advantage to Mark's 1). There should be no reason that I know that a path to a font file would fail, if the path is correct and the font is not corrupt in some way or malformed. – fmw42 Dec 10 '18 at 18:00