[Gllug] Making menu images from text: Solution

robin.c.smith at bt.com robin.c.smith at bt.com
Mon Feb 4 13:49:44 UTC 2002


I've just spent 5 minutes scripting up the solution base on the
recommendations in the list to make a graphic menu item.
I'll release the source code as GPL :-)

Usage: ./makegraphic "#ffffff" "#ff0000" "Transactions" 10 > /tmp/abc.pnm 

Changes required:-

1. Use getopt to read input parameters
2. Check for errors
3. Check that text is not bigger than menu picture

Any one feeling bored enough to fix these changes?

The fonts suck big time :-(

Robin

#!/bin/bash
# This script is called makegraphic

BGCOLOUR=$1
FGCOLOUR=$2
TEXT=$3
SIZE=$4

MENUWIDTH=150
MENUHEIGHT=20

ppmmake "${BGCOLOUR}" 500 500 | \
ppmlabel -colour "${FGCOLOUR}" -size ${SIZE} -text "${TEXT}" | \
pnmcrop > /tmp/menu$$.pnm 2>/dev/null

WIDTH=$(pnmfile /tmp/menu$$.pnm | awk '{ print $4 }')
HEIGHT=$(pnmfile /tmp/menu$$.pnm | awk '{ print $6 }')

ppmmake "${BGCOLOUR}" ${MENUWIDTH} ${MENUHEIGHT} > /tmp/bg$$.pnm

OFFSETX=$(echo "($MENUWIDTH-$WIDTH)/2" | bc)
OFFSETY=$(echo "($MENUHEIGHT-$HEIGHT)/2" | bc)
                           
pnmpaste -replace /tmp/menu$$.pnm ${OFFSETX} ${OFFSETY} /tmp/bg$$.pnm

rm /tmp/menu$$.pnm
rm /tmp/bg$$.pnm   


-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list