#! /bin/csh -f # # print a list of filename patterns onto the image # of a 4.65" CD label # # goto Setup Help: cat << EOF usage: filestamp.com label.gif textstrings.txt EOF exit 9 Setup: # label is 4.65" wide, 1.6" center # set tempfile = /tmp/filestamp_temp$$ set tempfile = tempfile set label = "" set labeltext = "" set pointsize = 14 foreach arg ( $* ) file $arg | grep "ASCII text" >& /dev/null if(! $status) then set labeltext = "$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}'` continue endif end rm -f ${tempfile} >& /dev/null # default to today's date if (! -e "$labeltext") 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 text printing compatibility convert -size 10x10 -depth 1 -font $font -annotate 0x0+5+5 "xxx" NULL:white BMP:/dev/null >& /dev/null if(! $status) then set NEWMAGICK 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 15*$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 psize_file = `echo $pointsize $dpi | awk '{printf "%d", $1*$2/100}'` ################################################## # FILENAMES # # There is room for ~16 legible filenames on the DVD # # ############################# # measure the size of each printed text string in pixels echo -n "" >! ${tempfile}.labelsizes set slots = `cat $labeltext | wc -l` foreach slot ( `awk 'NR<=16{++n; print n}' $labeltext` ) # dump text into a file awk -v slot=$slot '{++n} n==slot{print;exit}' $labeltext >! ${tempfile}label # measure the printed label if($?NEWMAGICK) then convert -box white -font $font -pointsize $psize_file \ -annotate 0x0+10+$middle "@${tempfile}label" -$trim \ ${tempfile}scratch.pgm ${tempfile}cropped.pgm else convert -box white -font $font -pointsize $psize_file \ -draw "text 10,$middle '@${tempfile}label'" -$trim \ ${tempfile}scratch.pgm ${tempfile}cropped.pgm endif set label_size = `awk -v dpi=$dpi '! /^#/{++n} n==2 && NF==2{print $1/dpi,$2/dpi;exit} n>4{exit}' ${tempfile}cropped.pgm` echo "$slot $label_size LABEL" >> ${tempfile}.labelsizes rm -f ${tempfile}cropped.pgm ${tempfile}label >& /dev/null end set height = `awk '{print $3;exit}' ${tempfile}.labelsizes` # format: slot# length(inches) height(inches) "LABEL" rm -f ${tempfile}scratch.pgm >& /dev/null rm -f ${tempfile}cropped.pgm >& /dev/null #################################### # define locations of "slots" on the label surface # echo "2.325" | awk '{print 2*sqrt(2.3^2 - ($1-2.325)^2)}' # accessible area is [0.22,1.5] and [3.15,4.43] # hard-code numbered "slots" # echo "0.25" | awk '{for(i=1;i<=8;++i){printf "%2d %.2f %.2f\n", i, $1, 2*sqrt(2.25^2 - ($1-2.38)^2); $1+=0.17}}' # echo "3.3" | awk '{for(i=1;i<=8;++i){printf "%2d %.2f %.2f\n", i+8, $1, 2*sqrt(2.25^2 - ($1-2.38)^2); $1+=0.17}}' cat << EOF | head -$slots | sort -n >! ${tempfile}.slots 10 3.47 3.94 11 3.64 3.73 7 1.27 3.91 6 1.10 3.70 9 3.30 4.11 8 1.44 4.09 12 3.81 3.47 5 0.93 3.44 13 3.98 3.16 4 0.76 3.12 14 4.15 2.78 3 0.59 2.73 15 4.32 2.28 2 0.42 2.21 16 4.49 1.56 1 0.25 1.45 EOF # format: slot# vertical_pos(inches) maxlength(inches) # put everything into one file cat ${tempfile}.slots ${tempfile}.labelsizes |\ awk '{++n;slot[n]=$2" "$3} /LABEL/{++i;print $1,$2,slot[i]}' |\ cat >! ${tempfile}.positions # format: label# labellength(inches) vertical_pos(inches) maxlength(inches) ######################### # do some swapping to make things fit better? # pad the label file to prevent wrap-around set pad = `awk -v dpi=$dpi '$2>2.2{printf "%d\n", ($2-2.2)*dpi}' ${tempfile}.labelsizes | sort -n | tail -1` if("$pad" != "") then #convert -bordercolor white -border ${pad}x0 $label ${label}.miff set paddedsize = `echo $labelsize x $pad | awk -F "x" '{print $1+$3"x"$2}'` composite -size ${paddedsize} -geometry +${pad}+0 ${label} NULL:white ${label}.miff if(! -e ${label}.miff) then convert -bordercolor white -border ${pad}x0 $label ${label}.miff endif mv ${label}.miff ${label} endif rm -f ${tempfile}.slots >& /dev/null rm -f ${tempfile}.labelsizes >& /dev/null ############################ # now actually print filenames onto the label image foreach line ( `awk '{++n; print n}' $labeltext` ) # recover the position to print to set pos = `awk -v line=$line 'NR==line{print $3,$4,$2;exit}' ${tempfile}.positions` set pos = `echo "$pos $dpi" | awk '$3>$2{excess=($3-$2)/2} {printf "%d %d", $NF*(2.325-$3/2-excess), $NF*$1}'` set pos = `echo $pos $pad | awk '{print $1+$3,$2}'` set posc = `echo $pos | awk '{print $1","$2}'` set posp = `echo $pos | awk '{print "0x0+"$1"+"$2}'` # dump text into a file awk -v line=$line '{++n} n==line{print;exit}' $labeltext >! ${tempfile}label set labelstring = `cat ${tempfile}label` echo "printing $labelstring onto $label at $pos" # print it into the graphics if(! $?NEWMAGICK) then convert -font $font -pointsize $psize_file \ -draw "text $posc '@${tempfile}label'" \ $label ${label}.miff else convert -font $font -pointsize $psize_file \ -annotate $posp "@${tempfile}label" \ $label ${label}.miff endif mv ${label}.miff ${label} end rm -f ${tempfile}label >& /dev/null rm -f ${tempfile}.positions >& /dev/null # undo the pad if("$pad" != "") then convert -bordercolor white -crop ${labelsize}+${pad}+0 $label ${label}.miff # fix new bug convert -page ${labelsize}+0+0 ${label}.miff ${label} rm -f ${label}.miff endif exit ################################################# ################################################# #################################################