#!/usr/bin/awk -f
#
# makehtmlgallery6 -- makes HTML image gallery and thumbnail page
# http://www.tnt.uni-hannover.de/~purnhage/software/makehtmlgallery6
#
# requires ImageMagick 5.2 or newer
# http://www.imagemagick.org/www/convert.html
#
# This program is available under the terms of the GNU General Public
# License (GPL). All usual disclaimers apply!
#
# Heiko Purnhagen (purnhage@tnt.uni-hannover.de)
# HP 20021127 20021128 20030317 20030827 20040926
# modified by Carsten Stolzenbach
# CS 20030817 20030827
# HP 20051115 adaptions for SuSE 10.0
# HP 20060604 re-design with gray frames
# HP 20070501 minor fix, removing size, using resize only imgsize='"800x800>"'
# HP 20070513 makehtmlgallery6: added USM
# HP 20070518 switched to -quality 90 (from 85)
function makepict(img1, img2, img3, img2caption, title) {
img2html = destdir "/" img2 key "_.html";
if (curpicts == thumbcols) {
print "";
curpicts = 0;
curcols = curcols + 1;
}
if (curpicts == 0)
print "
";
curpicts = curpicts+1;
system ("rm -f " img2html);
printf " ",img2,img2;
if (idxname) {
printf " %s",img2;
}
printf " | \n";
print "\n\
\n\
\n\
\n\
" title " - " img2 "\n\
\n\
\n\
\n\
" > img2html;
printf "" > img2html;
if (img1 == "") {
printf "[prev] " > img2html;
}
else {
printf "[prev] " > img2html;
}
printf "[index] " > img2html;
if (img3 == "") {
printf "[next]" > img2html;
}
else {
printf "[next]" > img2html;
}
printf "
\n" > img2html;
if (img2caption != "") {
tmpcaption = img2caption;
}
else if (defcap != "") {
tmpcaption = defcap;
}
else {
tmpcaption = img2;
}
print "" tmpcaption "
" > img2html;
printf " img2html;
close(img2html);
system ("identify -format 'width=\"%w\" height=\"%h\"' " destdir "/" img2 " >> " img2html);
printf " src=\"%s\" alt=\"%s\" border=\"0\"> |
\n",img2,img2 >> img2html;
if (footer!="") {
print "" footer "
" >> img2html;
}
print "\n\
\n\
" >> img2html;
}
BEGIN {
print "usage: \\ls *.jpg | makehtmlgallery4 >! index.html" > "/dev/stderr";
print "or: makehtmlgallery4 title=\"TITLE\" < imglist >! index.html" > "/dev/stderr";
print "or: makehtmlgallery4 key=_xxx title=\"TITLE\" < imglist >! index_xxx.html" > "/dev/stderr";
print "or: makehtmlgallery4 key=_xxx srcdir=\"???canon\" destdir=size-800 \\" > "/dev/stderr";
print " imgsize=\'\"800x800>\"\' forceconvert=1 \\" > "/dev/stderr";
print " thumbcols=6 thumbsize=100x100 idxname=1 \\" > "/dev/stderr";
print " title=\"All My Images\" idxcap=\"[back]\" \\" > "/dev/stderr";
print " defcap=\"My Image\" footer=\"Photo: A. Nonymus 2006\" \\" > "/dev/stderr";
print " backlink=\"../index.html\" \\" > "/dev/stderr";
print " < imglist >! size-800/index_xxx.html" > "/dev/stderr";
print " imglist is a text file with a single image file name per line," > "/dev/stderr";
print " optionally followed by a rotation angle (deg cw) and/or comment/caption." > "/dev/stderr";
print " If imgsize is specified, images in srcdir are scaled & rotated to destdir." > "/dev/stderr";
print " title specifies the title of the index HTML page (default \"Image Galery\")." > "/dev/stderr";
print " idxname=1 adds filenames to thumbnails on index page." > "/dev/stderr";
print " defcap is default (instead of filename) if no caption in imglist." > "/dev/stderr";
print " footer is appened below all photo HTML pages." > "/dev/stderr";
print " backlink is added to index HTML page." > "/dev/stderr";
print "" > "/dev/stderr";
thumbcols = 6;
thumbsize = "100x100";
srcdir = ".";
destdir = ".";
imgsize = "";
forceconvert = 0;
title = "Image Gallery";
# srcdir = "???canon";
# destdir = "size-800";
# imgsize = "800x800";
idxcap = "";
idxname = 0;
defcap = "";
footer = "";
backlink = "";
img1 = "";
img2 = "";
img3 = "";
img2caption = "";
img3caption = "";
curpicts = 0;
curcols = 0;
}
{
if (NR==1) {
split(thumbsize,twh,"x");
if (idxname) {
tdstring = "width=\"" twh[1]+20 "\" height=\"" twh[2]+35 "\"";
}
else {
tdstring = "width=\"" twh[1]+20 "\" height=\"" twh[2]+20 "\"";
}
if (system("test -e " destdir "/thumbs")) {
print "making directory thumbs" > "/dev/stderr";
system ("mkdir -p " destdir "/thumbs");
}
print "\n\
\n\
\n\
\n\
" title "\n\
\n\
\n\
\n\
\n\
" title "
";
if (backlink!="") {
print "[back]
";
}
if (idxcap!="") {
print "" idxcap "
";
}
print "";
}
if (imgsize != "") {
rot = 0+$2;
if (forceconvert ||
!system("test " srcdir "/" $1 " -nt " destdir "/" $1)) {
print "generating " destdir "/" $1 > "/dev/stderr";
system ("convert " srcdir "/" $1 " +profile \"*\" -resize " imgsize " -rotate " rot " -unsharp 1x1+0.5+0 -quality 90 -sampling-factor 1x1 " destdir "/" $1);
}
}
if (forceconvert ||
system("test -e " destdir "/thumbs/" $1 "_thumb.jpg") ||
!system("test " destdir "/" $1 " -nt " destdir "/thumbs/" $1 "_thumb.jpg")) {
print "converting " destdir "/" $1 " to " destdir "/thumbs/" $1 "_thumb.jpg" > "/dev/stderr";
system ("convert " destdir "/" $1 " +profile \"*\" -resize " thumbsize " -unsharp 1x1+0.5+0 -quality 90 -sampling-factor 1x1 " destdir "/thumbs/" $1 "_thumb.jpg");
}
if (!system("test -e " destdir "/thumbs/" $1 "_thumb.jpg")) {
print "adding " $1 " (thumbs/" $1 "_thumb.jpg) to gallery" > "/dev/stderr";
img1 = img2;
img2 = img3;
img2caption = img3caption;
img3 = $1;
captionstart = length($1)+2;
if (match($2,"[0-9+\\-]")) {
captionstart += length($2)+1;
}
img3caption = substr($0,captionstart);
if (img2 != "") {
makepict(img1, img2, img3, img2caption, title);
}
}
}
END {
if (img3 != "") {
makepict(img2, img3, "", img3caption, title);
for (;curpicts ";
print ""
}
print "
";
print "
\n\
generated by \
\
makehtmlgallery6 (v20070518) on";
system ("date -R");
print "
\n\
\n\
\n\
";
}