#! /bin/csh -f # # print a title onto the top and bottom # of an image of a 4.65" CD label # # goto Setup Help: cat << EOF usage: titlestamp.com label.gif TopTitle [BottomTitle] EOF exit 9 Setup: # label is 4.65" wide, 1.6" center # set tempfile = /tmp/mid_label$$ set tempfile = tempfile set label = "" set titles = "" set pointsize = "25" set title1_pos = "2.325 0.3" set title2_pos = "2.325 4.5" set titles = ( "" "" ) set i = 0 set j = 0 while ( $i < $#argv ) @ i = ( $i + 1 ) set arg = "$argv[$i]" if(-e "$label" && $j < 2) then @ j = ( $j + 1 ) set titles[$j] = "$arg" continue endif identify $arg >&! ${tempfile} if(! $status) then # this is some kind of image set label = "$arg" set labelsize = `awk -F "[x ]" '{print $3"x"$4+0}' ${tempfile}` # recover dpi because we know how big a CD label is if(! $?dpi) set dpi = `echo $labelsize | awk '{print $1/4.65}'` endif rm -f ${tempfile} >& /dev/null end # default to something? if ("$titles[1]" == "") goto Help if(! -e "$label") goto Help ################################################# # check font compatibility set font = Helvetica convert -size 10x10 -depth 1 -font $font -draw "text 5,5 xxx" NULL:white BMP:/dev/null >& /dev/null if($status) then set font = Arial endif ################################################# # check imagemagick trim compatibility set trim = "trim" convert -size 10x10 -depth 1 -fill black -draw "point 5,5" -$trim NULL:white BMP:/dev/null >& /dev/null if($status) then set trim = "crop 0x0" endif ################################################# # create PGM for measuring printed text set maxsize = `echo $dpi | awk '{print 5*$1"x"2*$1}'` set middle = `echo $dpi | awk '{print 1*$1}'` convert -size $maxsize -depth 8 -fill black -draw "color 0,0 reset" NULL: ${tempfile}scratch.pgm set pointsize = `echo $pointsize $dpi | awk '{printf "%d", $1*$2/100}'` ################################################# # print the titles onto the image foreach title ( 1 2 ) # location of the title set inch_pos = "$title1_pos" if($title != 1) set inch_pos = "$title2_pos" set title = "$titles[$title]" if ( "$title" == "" ) continue # measure the title convert -box white -font $font -pointsize $pointsize \ -draw "text 10,$middle '$title'" -$trim \ ${tempfile}scratch.pgm ${tempfile}cropped.pgm set inch_size = `awk -v dpi=$dpi '! /^#/{++n} n==2 && NF==2{print $1/dpi,$2/dpi;exit} n>4{exit}' ${tempfile}cropped.pgm` # change point size if the title is too big set shrink = `echo "1.5 $inch_size" | awk '$1>$2{$1=$2} {print $1/$2}'` set inch_size = `echo "$shrink $inch_size" | awk '{print $1*$2}'` set pointsize = `echo "$shrink $pointsize" | awk '{printf "%d", $1*$2}'` # now actually print the title onto the label image echo "printing $title onto $label at $inch_pos" set pixel_pos = `echo $inch_pos $inch_size $dpi | awk '{printf "%d,%d", $1*$NF-($3/2)*$NF,$2*$NF}'` convert -fill black -font $font -pointsize $pointsize -draw "text $pixel_pos '$title'" $label ${label}.miff mv ${label}.miff $label end rm -f ${tempfile}scratch.pgm >& /dev/null rm -f ${tempfile}cropped.pgm >& /dev/null exit ################################################# ################################################# #################################################