#! /bin/tcsh -f # # print a date onto the image of a 4.65" CD label # # goto Setup Help: cat << EOF usage: datestamp.com label.gif "Dec 28 2002" EOF exit 9 Setup: # label is 4.65" wide, 1.6" center # set tempfile = /tmp/datestamp_label$$ set tempfile = tempfile set label = "" set date = "" foreach arg ( $* ) if(-e "$label") then set date = "$date $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 today's date if ("$date" == "") set date = `date | awk '{print $2,$3,$NF}'` 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 ################################################# # print the date onto the image # location and size of the date string set psize_date = `echo 17 $dpi | awk '{printf "%d", $1*$2/100}'` set text1 = `echo 3.175 1.745 $dpi | awk '{printf "%d,%d", $1*$NF,$2*$NF}'` # measure the date string convert -box white -font $font -pointsize $psize_date \ -draw "text 10,$middle '$date'" -$trim \ ${tempfile}scratch.pgm ${tempfile}cropped.pgm set date_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 string is too big set shrink = `echo "1.6 $date_size" | awk '$1>$2{$1=$2} {print $1/$2}'` set date_size = `echo "$shrink $date_size" | awk '{print $1*$2}'` set psize_date = `echo "$shrink $psize_date" | awk '{printf "%d", $1*$2}'` # now actually print the date onto the label image set date_pos = `echo 3.75 1.745 $date_size $dpi | awk '{printf "%d,%d", $1*$NF-($3/2)*$NF,$2*$NF}'` convert -fill black -font $font -pointsize $psize_date -draw "text $date_pos '$date'" $label ${label}.miff mv ${label}.miff ${label} rm -f ${tempfile}scratch.pgm >& /dev/null rm -f ${tempfile}cropped.pgm >& /dev/null exit ################################################# ################################################# #################################################