#!/usr/bin/awk -f # # makehtmlgallery7 -- makes HTML image gallery and thumbnail page # # usage: ls *.jpg | makehtmlgallery7 > index.html # (see below for more examples) # # http://www.heikopurnhagen.net/software/makehtmlgallery7 # # This program is available under the terms of the GNU General Public # License (GPL). All usual disclaimers apply! # # requires ImageMagick 5.2 or newer # http://www.imagemagick.org/www/convert.html # # requires exiftool # http://www.sno.phy.queensu.ca/~phil/exiftool/ # # Heiko Purnhagen (mail@heikopurnhagen.net) # 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) # HP 20070905 makehtmlgallery7: keep EXIF data, mouseover highlighting # HP 20070906 going from q90 to q93 (but not q95) for pic+thumb # HP 20070907 span display:block makes W3C happy # HP 20070908 left/up/right arrows, accesskey: b,i,n # HP 20070908b default usemap=0 (for EXIF Viewer on Firefox) # HP 20070910 fractional usemap=0 .. 1 (upper fraction of image) # HP 20080317 added -m to exiftool (ignore minor errors, like broken embedded images) # HP 20080322 fixed bug in case of forceconvert=1 # HP 20080425 closing files again (for long lists) # HP 20080811 usage in comment, fixed source URL # HP 20080816 print help only if ARGC==1 # HP 20090316 stripping rotation from EXIF of scaled JPEG # add caption and footer in img attribute # HP 20090401 make altstr and altstrthumb safe (no ") # HP 20090913 remove all from title string in html header # HP 20090930 added option idxlnkanc to enable anchors in index links # HP 20091004 picture table with cellspacing=0 # HP 20101030 changed date format, compatible with BSD + GNU date # HP 20110101 abort with error in case of ambiguous image file name # HP 20120419 makehtmlgallery7hd for 1920x1080 function makepict(img1, img2, img3, img2caption, title) { if (curpicts == thumbcols) { print ""; curpicts = 0; curcols = curcols + 1; } if (curpicts == 0) print ""; curpicts = curpicts+1; if (img2caption != "") { tmpcaption = img2caption; } else if (defcap != "") { tmpcaption = defcap; } else { tmpcaption = img2; } if (title == tmpcaption) { titlestr = title " - " img2; } else { titlestr = title " - " tmpcaption; } if (footer!="") { altstr = titlestr " - " footer; } else { altstr = titlestr; } altstrthumb = tmpcaption; gsub("\"","",altstr); gsub("\"","",altstrthumb); img2html = destdir "/" img2 key "_.html"; system ("rm -f " img2html); getwh = "identify -format '%wx%h' " destdir "/thumbs/" img2 "_thumb.jpg"; getwh | getline wxh; close(getwh); split(wxh,wh,"x"); printf ""; printf ""; printf "\"""; if (idxname) { printf "
" img2 ""; } printf "\n"; if (idxlnkanc) { idxlnk = "#" img2; } else { idxlnk = ""; } print "\n\ \n\ \n\ \n\ " gensub("<[^>]*>","","g",titlestr) "\n\ \n\ \n\ \n\
" > img2html; printf "\n" > img2html; if (img1 == "") { printf "\n" > img2html; } else { printf "\n" > img2html; } printf "\n" > img2html; if (img3 == "") { printf "\n" > img2html; } else { printf "\n" > img2html; } printf "
\"prev\"\"prev\"\"index\"\"next\"\"next\"
\n" > img2html; print "

" tmpcaption "

" > img2html; getwh = "identify -format '%wx%h' " destdir "/" img2; getwh | getline wxh; close(getwh); split(wxh,wh,"x"); printf "
" > img2html; if (!usemap) { printf "" > img2html; } printf " img2html; printf "width=\"%d\" height=\"%d\" ",wh[1],wh[2] > img2html; printf "border=\"0\" src=\"" img2 "\" alt=\"" altstr "\"" > img2html; if (usemap) { printf " usemap=\"#pin\"" > img2html; } printf ">" > img2html; if (!usemap) { printf "" > img2html; } printf "
\n" > img2html; if (usemap) { wt = int(wh[1]/3); hm = int(wh[2]*usemap); if (hm < 1) hm = 1; if (hm > wh[2]) hm = wh[2]; printf "\n" > img2html; if (img1 != "") { printf "\"prev\"\n",1,1,wt,hm > img2html; } printf "\"index\"\n",wt+1,1,wh[1]-wt-1,hm > img2html; if (img3 != "") { printf "\"next\"\n",wh[1]-wt,1,wh[1],hm > img2html; } printf "\n" > img2html; } if (footer!="") { print "

" footer "

" > img2html; } print "
\n\ \n\ " > img2html; close(img2html); } BEGIN { if (ARGC==1) { print "usage: \\ls *.jpg | makehtmlgallery7 >! index.html" > "/dev/stderr"; print "or: makehtmlgallery7 title=\"TITLE\" < imglist >! index.html" > "/dev/stderr"; print "or: makehtmlgallery7 key=_xxx title=\"TITLE\" < imglist >! index_xxx.html" > "/dev/stderr"; print "or: makehtmlgallery7 key=_xxx srcdir=\"???canon\" destdir=size-800 \\" > "/dev/stderr"; print " imgsize='\"800x800>\"' forceconvert=1 usemap=1 idxlnkanc=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; usemap = 0; idxlnkanc = 0; title = "Image Gallery"; # srcdir = "???canon"; # destdir = "size-800"; # imgsize = "800x800"; imgsize = "1920x1080"; 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"); } system ("( cd " destdir " ; echo 'H4sIAIJ94kYCA+3XP0gCURzA8af0R2wooqXtgqDIlPfuz3tJU0t1RHtOcYOekoadZ+jQpiEubQ7S 0pZDYENTDQ0JQXR7RDo0SENbILbUnVJbhMOJV7/Pcrx3t37f7108HNEFPkOoElBjEWQLbKKiaD0J ljpPTLrrDsJTRDBlWGSEFyjCRMCMIg6jPkindEXjOJRMa7tRRQ3//F1YS6E/Z01eXQoqHJpAJy5r /fFlpj3k8pobi9au9R6553JHlbvX8ZXCWy70XHtI1P2NTH5ELk++V3xjh2e+kn4g7BmtYbSMgEOk k3bX31v/giSZ/fMS46H/Qe3fc14O+m+2mJH1eoqjclk+DcQv95PH97c7G5rRhP4dRIupUbsvAL/3 z777N9O35r95AED/g9b/fLf/zcJUPvRSayfqcsOzPztdbJbcvseF7atrXXu6MFrrLjgAHCNu3v9V TcnaeQT0MP95Sjv9M4ah/z7377bW1WoV7v//bf7bfAD0MP95hq3/f5FI0P/A9Q/zHwAAAAAAAAAA AAAAAJzjEzHzWXwAKAAA' | perl -MMIME::Base64 -ne 'print decode_base64($_)' | gunzip -c | tar x )"); print "\n\ \n\ \n\ \n\ " gensub("<[^>]*>","","g",title) "\n\ \n\ \n\ \n\
\n\

" title "

"; if (backlink!="") { print "

[back]

"; } if (idxcap!="") { print "

" idxcap "

"; } print ""; } if (imgsize != "") { cntsrc = "ls " srcdir "/" $1 " | wc"; cntsrc | getline numsrc; close(cntsrc); split(numsrc,numsrcar); if (numsrcar[1]==0) { print "ERROR: missing source file " srcdir "/" $1 > "/dev/stderr"; exit; } if (numsrcar[1]>1) { print "ERROR: ambiguous source file " srcdir "/" $1 > "/dev/stderr"; exit; } rot = 0+$2; if (forceconvert || !system("test " srcdir "/" $1 " -nt " destdir "/" $1)) { print "generating " destdir "/" $1 > "/dev/stderr"; # system ("convert " srcdir "/" $1 " -resize " imgsize " -rotate " rot " -unsharp 1x1+0.5+0 -quality 93 -sampling-factor 1x1 " destdir "/_makehtmlgallery_tmp_" $1); system ("convert " srcdir "/" $1 " -rotate " rot " -resize " imgsize " -unsharp 1x1+0.5+0 -background black -gravity center -extent " imgsize " -quality 97 -sampling-factor 1x1 " destdir "/_makehtmlgallery_tmp_" $1); system ("rm -f " destdir "/" $1); system ("exiftool -n -Orientation=1 -m -thumbnailimage= -previewimage= -o " destdir "/" $1 " " destdir "/_makehtmlgallery_tmp_" $1 " > /dev/stderr"); system ("rm -f " destdir "/_makehtmlgallery_tmp_" $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 93 -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 \ \ makehtmlgallery7hd (v20120419) on"; system ("date \"+%a %F %T\""); print "

\n\
\n\ \n\ "; } #--