#!/bin/sh
# genethumb.sh - GÈnÈration de thumbnails mortels de ta mËre
# (c)  3 Jan 1998: version 0.0.4 by Samuel Hocevar <sam@via.ecp.fr>
#     22 May 2000: version 0.0.5 by Samuel Hocevar <sam@via.ecp.fr>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

version=0.0.5

if [ -w index.html ]
then
  echo "saving index.html to index.html~"
  mv index.html index.html~
fi

cat > index.html << EOF










<head>
        <meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
        <title>page d'accueil</title>
        <link rel="stylesheet" href="../monsite.css" style="text/css" type="text
/css">
</head>

<body bgcolor="#63d1ff">















<hr />
EOF

compteur=0

echo "<center><table width=\"95%\" cellspacing=\"5\"><tr>" >> index.html

for file in *
do
  # on vÈrifie que l'image n'est pas dÈjý un thumbnail ou une page html, et a
  # une extension quelconque (ý amÈliorer un peu)
  if echo "$file" | grep -v tn_ | grep -v "\.html" | grep "\." 1>/dev/null 2>&1
  then
    failed=0
    newfile="tn_"`echo $file | sed 's/\.[^\.]*//'`.png
    if [ -r $newfile ]
    then
      echo $newfile : already exists
    else
      echo -n "$file -> $newfile : "
      convert -geometry 120x90 $file $newfile 2>&1 > /dev/null
      if [ ! -r $newfile ]
      then
        echo failed creating.
	failed=1
      else
        echo done.
      fi
    fi
    if [ "$failed" = "0" ]
    then
      compteur=`echo $compteur+1 | bc`
      coordinates=`identify $newfile | awk '{ print $2 }'`
      oldcoords=`identify $file | awk '{ print $2 }'`
      j=`echo $file | cut -b1-17`
      if [ "$file" != "$j" ]
      then
        j=$j...
      fi
      echo "<td align=\"center\" width=\"20%\"><a href=\""$file"\"><img alt=\""$i" ("$oldcoords")\" width=\""`echo $coordinates | cut -f1 -dx`"\" height=\""`echo $coordinates | cut -f2 -dx`"\" src=\"$newfile\" border=\"1\" /><br />"$j"<br />"$oldcoords"</a></td>" >> index.html
      if [ "$compteur" = "5" ]
      then
        #echo "</tr></table><table width="95%" cellspacing=5><tr>" >> index.html
	echo "</tr><tr>" >> index.html
      compteur=0
      fi
    fi
  fi
done

cat >> index.html << EOF
</tr></table></center>

</body>
</html>
EOF
