2008-08-05

Imagemagick based automation tool

I needed a tool to generate some images for MRTG index page. Imagemagick has some programs to create and convert images. Very useful guide is on Imagemagick site. Look at this:

for STRING in MySQL1 MySQL2 Loghost Backup; do
# Variables "invented" experimentally
A=3; B=70
# Length of string
X=${#STRING}
# Where to start to draw the label
Y=$((A*X+B))
# Imagemagick tool with PostScript command to rotate label
convert -size 20x120 xc:white \
-font /usr/share/fonts/truetype/ttf-dejavu/DejaVuSerifCondensed.ttf \
-pointsize 16 \
-fill black \
-draw "rotate -90 text -$Y,15 '$STRING'" /tmp/${STRING}.png
done

Some experiments gave me variables for equation to center the label vertically. I can't do it in PostScript.

No comments: