#!/bin/bash
resolution=72
pixwidth=$((resolution*50/10))
linerwidth=$((resolution*4))
liner=0
if [ -e $1-card.txt ]; then
    title=$(head -1 $1-card.txt)
else
    title=$2
fi
if [ "$title" = "" ] ; then
    echo Oops - no album title in .txt file or on command line
    exit
fi
rm -f /tmp/$1.ps
cat << STOP > /tmp/$1.ps
%!
/Palatino-Bold findfont
10 scalefont
setfont
420 ($title) stringwidth pop 2 div sub 470 moveto
($title) show
90 rotate
92 -600 translate
0 0 moveto
gsave
STOP
if [ -e $1-card.txt ]; then
    texttocard < $1-card.txt >>  /tmp/$1.ps
else
cardfile=$1-b-autojoin.tif
if [ -e $1-card.tif ] ; then
  cardfile=$1-card.tif
fi
tifftopnm $cardfile | ppmtopgm | \
  pnmscale -xysize $pixwidth  $pixwidth | \
  pnmtops -width 5 -height 5 -dpi 300 -noturn | \
  fgrep -v showpage >> /tmp/$1.ps
fi
cat << STOP >> /tmp/$1.ps
grestore
[1 4] 0 setdash
0 setlinewidth
372 0 moveto
372 600 lineto
390 0 moveto
390 600 lineto
-15 0 moveto
-15 600 lineto
-33 0 moveto
-33 600 lineto
stroke
[] 0 setdash
statusdict begin
/manualfeed true def
/manualfeedtimeout 20 def
showpage
STOP
cat /tmp/$1.ps
rm -f /tmp/$1.ps
