No text when annotating images with ImageMagick

If for some strange reason you don’t see any text, even when applying correct command, then you probably missing required font. To find out this, replace final image with info:.

convert dsc01377.jpg -font Courier -size 20 -draw "gravity south fill black  text 10,12 'text' fill white  text 11,11 'text' " info:

If you’ll see something like:

convert: unable to read font `/usr/share/fonts/type1/gsfonts/n022003l.pfb'.

– go ahead and install missing font.
I wonder why ImageMagick doesn’t dump this warning to stderr.

Monday, November 19th, 2007

Trimming two sides of an image

I had a task to trim two sides of an image in script using Imagemagick. If you were working with command-line Imagemagick, then you surely know perfect examples of its use. There is an instruction how to trim one side of the image. Expanding this example we can create the following command to trim bottom and right borders:

convert image.png -background white -splice 0x1 -background black -splice 0x1 -trim +repage -chop 0x1 -background white -splice 1x0 -background black -splice 1x0 -trim +repage -chop 1x0 trim.png

It works nicely, but if you know background color of your image, you can simplify command. Let’s assume that we want to trim white background. Just add one black dot in top left corner, trim the image and chop image by one pixel from left and top:

convert -background white xc:black -size 1x1 -page +1+1 image.png -mosaic -trim +repage -chop 1x1 trim.png

Saturday, July 14th, 2007