#!/bin/bash
# if background.gif and stylesheet.css exist, they will be used.

# copyright 2005 John Moyer, All rights reserved.
# mailto:jrm@rsok.com
# sponsored by http://www.A-Wee-Bit-of-Ireland.com/

DIRNAME=thumbnails$1
DATESTRING=`date +"%Y%b%d"`$1

export DIRNAME
export DATESTRING
export i

make_one_thumbnail() {
  convert $1  +profile "*" -resize "!43x32" thumbnails/$1
cat >> index.html << EOF

<div class="thumb">
<a href="${1}">
<img src="thumbnails/${1}" alt="" width=43 height=32>
</a>
<p>
<a href="${1}">
${1}</a>
</p></div>

EOF
}

export make_one_thumbnail

#type make_one_thumbnail

if [ -d $DIRNAME ]
then
  echo $DIRNAME already exists. Giving up.
  echo You could try '"'$0 _1'"' or something similar.
  exit -1
fi

if [ -f index.html ]
then
  echo index.html already exists. Giving up.
  exit 1
fi

mkdir $DIRNAME

if [ ! -d $DIRNAME ]
then
  echo failed to make $DIRNAME directory. Giving up.
  exit -1
fi

cat >> index.html << EOF
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
  <meta http-equiv="CONTENT-TYPE" content="text/html; charset=iso-8859-1">
EOF

echo   '<title>Photos '$DATESTRING'</title>' >> index.html

cat >> index.html << EOF2
<link type="text/css" rel="stylesheet" href="stylesheet.css" media="all">
<style type="text/css">
body {color: #000000;  background-color: white; }
a:link {color: blue; background-color: transparent;  }
a:visited {color: green; background-color: transparent;  }
a:hover {color: #ff0000; background-color: transparent;  }

div.spacer {
  clear: both;
  line-height: 0; height: 0;
  border: none;
  margin-left: 0;
  margin-top: 0;
  margin-right: 0;
  margin-bottom: 0;
  }

div.thumbnailcontainer {
  font-size: 100%;
  margin-left: 0;
  margin-right: 0;
  margin-top: 1em;
  margin-bottom: 1em;
  position: relative;
  min-width: 180px;	/* for IE7 */
/*  border: 1px solid green; */
  }

div.thumb {
  width: 160px;
  float: left;
  text-align: center; 
  margin-right: 5px; 
  margin-bottom: 5px;
  border: 2px solid green;
  overflow: auto;
  height: 7em;
  display: inline;
  }

div.thumb p {
  font-size: 100%;
/*  border: 1px; */
  margin-left: 1px;
  margin-right: 1px;
  margin-top: 1px;
  margin-bottom: 1px;
  clear: both;
  }

div.thumb img {
  display: block;
  margin-left: auto;
  margin-right: auto;
  margin-top: 0.5em;
  width: 43px;
  height: 32px;
  }
</style>
</head>
<body lang="en-US" text="#000000" link="#355e00" vlink="#000000"
 bgcolor="#ffffff" background="background.gif" dir="ltr">
EOF2

echo '  <h1 align="center">Photos '$DATESTRING'</h1>' >> index.html

cat >> index.html << EOF3
<div class="thumbnailcontainer">


EOF3

for i in *.jpg
do
  echo "make_one_thumbnail ${i}"
  make_one_thumbnail ${i}
done

cat >> index.html << EOF4

<div class="spacer">&nbsp;</div>
</div>

<p>
Web page created by 
<a href="http://www.rsok.com/~jrm/mkthumbindex.sh">mkthumbindex.sh</a>
written by John Moyer<br>
<a href="mailto:jrm@rsok.com">mailto:jrm@rsok.com</a><br>
Sponsored by
<a href="http://www.A-Wee-Bit-of-Ireland.com/">
http://www.A-Wee-Bit-of-Ireland.com/<sup>&#8482;</sup></a>
Your source in the USA for the finest Irish wool sweaters, ruanas,
capes, scarves and hats.
</p>
</body>
</html>
EOF4


#ls -axF $DIRNAME
echo thumbnails are in `pwd`/$DIRNAME
echo URL is file:///`pwd`/index.html
echo script by John Moyer, jrm@rsok.com
exit 0
