4

I'm am trying to generate test images with ImageMagick. The image needs to only contain text. Bluntly using the example on the IM site doesn't work:

convert -background lightblue -fill blue -font Roboto -pointsize 72 label:Anthony label.gif

Yields:

convert.im6: unable to read font `Roboto' @ warning/annotate.c/RenderType/853.
convert.im6: no images defined `label.gif' @ error/convert.c/ConvertImageCommand/3044.

So 1) what is required to be able to use font names (my whole desktop uses Roboto, so I assume it is properly installed, and other fonts names don't work either) and 2) if I remove the font spec I still get the second line and no output.

Am I missing something?

Using ImageMagick 6.7.7-10 2016-11-29 Q16 on Ubuntu 14.04.

xenoid
  • 8,396
  • 3
  • 23
  • 49

4 Answers4

6

It's a bug in the particular version of ImageMagick you are using, resulting from a incorrect backport of a bugfix patch.

The problematic patch is Debian patch 0161-Do-not-ignore-SetImageBias-bias-value. I can't tell if that was included in the 14-November-2016 security update to 8:6.7.7.10-6ubuntu3.2 or the 29-November-2016 security patch to 8:6.7.7.10-6ubuntu3.3 (or, at least, I didn't bother trying to figure it out, since it's not that important.) The patch was created as a backport of this security patch, but because of a reorganization of the logic in the file coders/label.c, the correction ended up being inserted in the wrong place.

In essence, the logic of label.c is as follows:

  1. if the image's size or pointsize is not specified, work out the best fit
  2. if the image's width was not specified, copy it from the computed width
  3. if the image's height was not specified, copy it from the computed height
  4. if the image's pointsize was not specified, copy it from the computed pointsize
  5. make some other relevant settings to image parameters
  6. Render the text into the image.

The security patch was intended to avoid step 6 if the resulting image size could not be used. This avoids a possible Denial of Service attack when ImageMagick is being used on a web back-end (which is common). It adds:

3a. If the image dimensions are unusable, immediately fail.

Unfortunately, in the version to which to patch is applied, the above steps were in a different order, with the third step being intermingled with step 5. (This made no real difference, as far as I can see, but it was a bit disorganized, which is probably why it was subsequently fixed.) The result is that the added step 3a is inserted before the image's height has been copied from the computed height. This causes the check to fail if the image did not originally have a height, even though a correct height had been computed at that point.

The instructions clearly indicate that a label: source does not require a -size (or -pointsize) parameter. But with the misplaced patch, this turns out to be incorrect; unless a height is specified in the geometry, the label will not be generated.

I haven't generated a bug report for this because it only applies to an outdated version of ImageMagic on an outdated version of Ubuntu (and possibly of Debian). It happens that I and OP are both using this outdated version of Ubuntu on some machine, and my recommendation to both of us is to upgrade. But in case anyone else has this problem, I'm answering the question (which I found when trying to research the identical problem on my machine.)

rici
  • 234,347
  • 28
  • 237
  • 341
3

Eventually got it to work using -size instead of -pointsize, and switched to caption since I can better control the position:

convert -background transparent -fill darkblue -font Roboto-Regular -size 200x100 -gravity center 'caption:Test' out.png
xenoid
  • 8,396
  • 3
  • 23
  • 49
1
convert -background lightblue -fill blue -font Arial -pointsize 72 label:"Anthony" label.gif

The above works fine for me on IM 6.9.7.0 Q16 Mac OSX

fmw42
  • 46,825
  • 10
  • 62
  • 80
0

Worked OK for me on a windows setup version 7 apart from the font error as I do not have that font installed. Setting it to arial removed the font error.

Try this to see if Imagemagick can see your font:

identify -list type

Otherwise I would try linking directly to your font with the path and putting the .ttf on the end. I assume your font is a .ttf one as Imagemagick supports that type and one other that I can not remember.

Out of interest your version is 4.5 years old.

Bonzo
  • 5,169
  • 1
  • 19
  • 27
  • Using `identify -list font` list the fonts and I can see I should have used 'Roboto-Regular'. Biut I sitll have the `no images defined` message. – xenoid Dec 18 '16 at 17:12