ImageMagick Text Handling 

help 

Using imagemagick command line parameters 

Excerpted from http://www.ibm.com/developerworks/library/l-graf/?ca=dnt-428 and http://www.imagemagick.org/Usage/text/

font 

-font helvetica sets the annotation's font to Helvetica. It is possible here to specify a path to a font file as well. This example badges the image so it can't be reused by other Web sites without permission, but it does so using a font that is in a non-standard location:

# convert -font fonts/1900805.ttf -fill white -pointsize 36 \
-draw 'text 10,475 "stillhq.com"' \
floriade.jpg stillhq.jpg
position 

You can adjust the position of the label in that extra space by adjusting the "-gravity" setting.

convert -background lightblue -fill blue  -font Candice \
        -size 160x70 -gravity center label:Anthony     label_gravity.gif

Of course if you do not set a "-size" for the label, no extra space will be available in the generated "label:" for "-gravity" to use, making it rather useless.

size 

Now for the best news. If the "-size" setting you give only contains just width or the height for the label, the text "-pointsize" will be set to best fit that dimension, and the other missing dimension will be auto-adjusted to best fit that text!

convert -background lightblue -fill blue -font Candice \
        -size 160x  label:Anthony     label_size_w.gif

Examples 

Excerpted from

ImageMagick v6 Example — Text to Image Handling
http://www.imagemagick.org/Usage/text/

Note, it was http://www.imagemagick.org/Usage/text/

Plain Text as Formated Pages of Images 

we can create a Chinese label (using a Chinese true-type font), by reading a UTF-8 encoded chinese text file.

convert -background lightblue -fill blue \
        -font SimSun -pointsize 48 label:@chinese_words.utf8 \
        label_utf8.gif

When drawing text, a large 'letter' sized page is created at the the current resolution (set with "-density"). By default (at 72 dpi) this will be '612x792' pixels in size, which for most purposes is very large.

Because the text is being 'drawn' onto a large canvas, you will likely want to remove all the unused space produced. This can be done by using the image operations "-trim", "+repage", then to make it look reasonable, re-adding some edge space using "-border". Of course you will also need to match the "-background" color you used as the "-bordercolor" you are re-adding.

identify -version | cut -d\  -f1-4 |\
  convert -background  lightblue  -fill blue  -pointsize 18 \
          text:-    -trim +repage  -bordercolor lightblue  -border 3 \
          text_trimmed.gif

In the above example "-trim" is used to remove the extra white space in the "text:" image. Otherwise the resulting image fills this web page. This however will also remove any leading spaces in front of a line!

There is however a interesting technique which will allow you to "-trim" the image down to the size of the actual text drawn onto the page, including any leading and trailing spaces in the input. This uses a special undercolor "-box":

echo "    Hello Cruel World    " |\
  convert -background  white -box lightblue  -fill blue  -pointsize 18 \
          text:-  -trim +repage  -bordercolor white  -border 3 \
          text_boxed.gif

If you use a transparent background color in the above, you can then flatten the trimmed image to convert the undrawn areas into the same color and the 'undercolor box' used.

echo "    Hello Cruel World    " |\
  convert -background  none  -box lightblue  -fill blue  -pointsize 18 \
          text:-  -trim +repage   -bordercolor lightblue  -border 3 \
          -background lightblue  -flatten    text_box_trimmed.gif

Compound Font Effects 

http://www.imagemagick.org/Usage/fonts/

text + outline 

Beveled Font

The "-shade" operator can be used to generate very nice looking 3D font with a beveled and smoothly curving edge.

convert -size 320x100 xc:black -font Candice -pointsize 72 \
          -fill white   -annotate +25+65 'Anthony' \
          -shade 140x60  font_beveled.jpg

This is much nicer than the stamped font, but shade will only generate grey-scale images. On the other hand their are a lot of methods which can replace the grey scale of the above result with whatever colors you need.

Better versions of these beveled fonts can be found in the examples on Shade 3D Highlighting. http://www.imagemagick.org/Usage/transform/#shade

Outline (Stroke) Font

The "-stroke" setting allows you to draw an outline of the font directly. Normally the stroke color is set to "none", so is not used. The thickness of the stroke is varied with "-strokewidth", which defaults to a good value of 1.

convert -size 320x100 xc:lightblue -font Candice -pointsize 72 \
        -fill white  -stroke black  -annotate +25+65 'Anthony' \
        font_stroke.jpg

And here is an example with a heavier stroke width of 3.

convert -size 320x100 xc:lightblue -font Candice -pointsize 72 \
        -fill white -stroke black -strokewidth 3 \
        -annotate +25+65 'Anthony'        font_stroke_3.jpg

Notice how the stroke color eats away not only the outside of the font, but the inside as well. For more detail see the results of my Stroke and Stroke Width Options.

Thin Stroke

By turning off the fill color, you can leave just the outline of the font.

convert -size 320x100 xc:lightblue -font Candice -pointsize 72 \
        -fill none  -stroke black   -annotate +25+65 'Anthony' \
        font_stroke_thin.jpg
Fuzzy Font

A straight spreading of a font color using "-blur" operator. This operator allows you to take a image and spread it out in all directions. This allows you to generate softer looking shadows, and or spray paint like effects. The following examples show the effects you can achieve with this.

convert -size 320x100 xc:lightblue -font Candice -pointsize 72 \
        -annotate +25+65 'Anthony'  -blur 0x3   font_fuzzy.jpg
Soft Outline

use the fuzzy font as the outline border. This is like using the original font as a mask to a spray gun. Note that the edge is very light as not only is the black color spread out, but the background color spreads inward.

convert -size 320x100 xc:lightblue -font Candice -pointsize 72 \
        -annotate +25+65 'Anthony'    -blur 0x5 \
        -fill white  -annotate +25+65 'Anthony'   font_outline_soft.jpg

documented on: 2006.11.19