#!/bin/sh

CORES=4
H=320
W=320

mkdir -p .thm
ls *.jpg | xargs -n1 -P$CORES -I{}  convert {} -thumbnail $Hx$W\> .thm/{}

(
    echo "<html><head><title>$(basename $PWD)</title></head><body>"
    for _file in *.jpg
    do
        (
            echo "<html><head><title>$_file</title></head><body>"
            echo "<center><h1>$_file</h1>"
            echo "<b><a href=../index.html>Back to Index</a></b><br><br>"
            echo "<img style='max-width: 90%; max-height: 90%;' src=../$_file></center>"
            echo "</body></html>"
        ) > .thm/$_file.html
        echo "<a href=\".thm/$_file.html\"><img height=$H src=\".thm/$_file\"></a>"
    done
    echo "</body></html>"
) > index.html
