rendered paste body#!/bin/bash# $Id: make-gallery.sh,v 1.1 2005/08/25 14:13:56 spliffy Exp $# Globalsexport height=180;export width=180;export normal_width=800;export normal_height=600;export rows=3;export dir_thumb="thumbs";export dir_normal="normal";export host=`uname -n`;export kernel=`uname -s`;export file_index="index.html";export file_image="image.html";export bordercolor="white";export borderwidth=40;export title=`basename "$PWD"`;# html optionsexport bgcolor="black";export textcolor="white";export linkcolor="silver";export linkvisted="gray";export linkactive="blue";while getopts h:w:n:j:r:f:c:b:t:g:x:l:v:a: o 2>/dev/nulldo case "$o" in h) height="$OPTARG";; w) width="$OPTARG";; n) normal_width="$OPTARG";; j) normal_height="$OPTARG";; f) file_image="$OPTARG";; c) bordercolor="$OPTARG";; b) borderwidth="$OPTARG";; t) title="$OPTARG";; g) bgcolor="$OPTARG";; x) textcolor="$OPTARG";; l) linkcolor="$OPTARG";; v) linkvisted="$OPTARG";; a) linkactive="$OPTARG";; *) echo "Usage: $0 [-h height] [-w width] [-n intermediate_width]"; echo " [-j intermediate_height] [-r rows] [-f image_file]"; echo " [-c border_color] [-b border_width] [index_file]"; echo ""; echo "OPTIONS:"; echo " -h number thumbnail image heigth (default $height)"; echo " -w number thumbnail image width (default $width)"; echo " -n number intermediate image width (default $normal_width)"; echo " -j number intermediate image heigth (default $normal_height)"; echo " -r number number of rows (default '$rows')"; echo " -f filename filename of the image html file (default '$file_image')"; echo " -c html_col thumbnail canvas color (default '$bordercolor')"; echo " -b number thumbnail border width (default $borderwidth)"; echo " -t string gallery title (default '$title')"; echo ""; echo "HTML OPTIONS:"; echo " -g background color (default '$bgcolor')"; echo " -x text color (default '$textcolor')"; echo " -l link color (default '$linkcolor')"; echo " -v link visited color (default '$linkvisted')"; echo " -a link active color (default '$linkactive')"; echo ""; echo "index_file is the html index file to be generated, default: '$file_index'."; echo ""; echo "VARIABLES:"; echo " You may override the html header and footer by setting the"; echo " following environment variables:"; echo " \$ export html_header='html code'"; echo " \$ export html_footer='html code'"; echo ""; echo "NOTE:"; echo " the actual thumbnail size is (thumnail width + thumbnail border * 2)."; echo ""; exit 1;; esacdoneif [[ ! -z $1 ]]; then shift $OPTIND-1;fiif [[ ! -z $1 ]]; then file_index="$1";fi;# html templatehtml_buffer="";if [[ -z $generated ]]; then generated=`date`;fi;if [[ -z $html_header ]]; then# html_header="<html>\n<head>\n<!-- generated @ $host ($kernel) \# $generated --><title>${title}</title>\n<body \# bgcolor=\"$bgcolor\" text=\"$textcolor\" link=\"$linkcolor\" \# vlink=\"$linkvisted\" alink=\"$linkactive\">\n"; html_header=`cat << EOT <html><head> <!-- generated @ $host ($kernel) $generated --> <title>${title}</title></head><body bgcolor="$bgcolor" text="$textcolor" link="$linkcolor" vlink="$linkvisted" alink="$linkactive">EOT`fi;if [[ -z $html_footer ]]; then html_footer="</body>\n</html>"fi;# image sizesexport size="${height}x$width";export normal_size="${normal_width}x${normal_height}";# output textfunction write { echo $1;}# create thumbnailsfunction create_thumbnails { if [[ ! -d $dir_thumb ]]; then write "Creating $dir_thumb"; mkdir $dir_thumb; fi; write "Resizing $dir_thumb ..."; cd $dir_thumb; cp ../*.jpg .; mogrify -format gif -thumbnail $size'>' -bordercolor $bordercolor \ -border $borderwidth -gravity center +repage '*.jpg'; rm *.jpg; cd ..;}# create reasonable sized images (browser friendly)function create_normal { if [[ ! -d $dir_normal ]]; then write "Creating $dir_normal"; mkdir $dir_normal; fi; write "Resizing $dir_normal ..."; cd $dir_normal; cp ../*.jpg .; mogrify -thumbnail ${normal_size}'>' +repage '*.jpg'; cd ..;}# buffer outputfunction add_to_buffer { html_buffer="${html_buffer}$1";}function create_line { jpeg="$1"; basename="$2"; img="<img src=\"$dir_thumb/${basename}.gif\" \ width=\"`expr $width + $borderwidth + $borderwidth`\" \ heigth=\"`expr $height + $borderwidth + $borderwidth`\" \ border=\"0\" alt=\"$jpeg\" title=\"$1\" />";# href="${file_image}?${jpeg}"; href="pages/${jpeg}.html"; link="<a href=\"$href\">$img</a>"; add_to_buffer "<td align=\"center\" >$link<p>${jpeg}</p></td>\n";}function create_navfile {a=`cat << EOT <html> <head> <!-- generated @ $host ($kernel) $generated --> <script type="text/javascript"><!-- function load_image() { var file = document.location.search; file = file.substr(1, file.length); document.getElementById("gallery_href").setAttribute("href", file); document.getElementById("gallery_image").setAttribute("src", "normal/" + file); } // --></script> <title>${1}</title> </head> <body bgcolor="black" text="white" link="silver" vlink="gray" alink="blue" onload="load_image();"> <div style="align: center; text-align: center;"> <a id="gallery_href" href="$dir_normal/"><img id="gallery_image" src="about:blank" border="0" /></a> </div> </body> </html>EOT`echo "$a" > $file_image;write "$file_image created.";}function create_page { # $1 = image name (without extension) # $2 last image name # $3 next image name # page_html=`cat << EOT<html><head> <!-- generated @ $host ($kernel) $generated --> <title>${title}</title></head><body bgcolor="$bgcolor" text="$textcolor" link="$linkcolor" vlink="$linkvisted" alink="$linkactive"><div></div></body></html>EOT`}function create_pages { if [[ ! -d pages ]]; then mkdir "pages"; fi files=`ls *.jpg`; last_page=""; this_page=""; next_page=""; for f in $files; do last_page="$this_page"; this_page="$next_page"; next_page="$f"; if [[ ! -z "$this_page" ]]; then write_page "$last_page" "$this_page" "$next_page" fi done last_page="$this_page"; this_page="$next_page"; next_page=""; write_page "$last_page" "$this_page" "$next_page"}function write_page { write "Generating page 'pages/$2.html' ..."; file_p_back="$1"; file_p_next="$3"; if [[ ! -z "$file_p_back" ]]; then file_p_back="${file_p_back}.html" fi if [[ ! -z "$file_p_next" ]]; then file_p_next="${file_p_next}.html" fi a=`cat << EOT <html> <head> <!-- generated @ $host ($kernel) $generated --> <title>${2}</title> <style type="text/css">a[href=""] {display: none;}</style> </head> <body bgcolor="black" text="white" link="silver" vlink="gray" alink="blue"> <h1>${2}</h1> <table width="100%" border="0"><tbody><tr> <td width="33%"><a href="${file_p_back}">« Back</a> </td> <td width="33%" align="center"><a href="../${file_index}">Übersicht</a></td> <td width="33%" align="right"> <a href="$file_p_next">Next »</a></td> </tr></tbody></table> <hr /> <br /> <div align="center"> <a href="../${2}"><img src="../$dir_normal/${2}" alt="$2" /></a> </div> <br /> <hr /> <table width="100%" border="0"><tbody><tr> <td width="33%"><a href="${file_p_back}">« Back</a> </td> <td width="33%" align="center"><a href="../${file_index}">Übersicht</a></td> <td width="33%" align="right"> <a href="$file_p_next">Next »</a></td> </tr></tbody></table> </body> </html>EOT`echo "$a" > "pages/${2}.html";}#create_navfile;create_thumbnails;create_normal;create_pages;# filesfiles=`ls *.jpg`;count=0;row_end=`expr $rows - 1`;add_to_buffer "<div style=\"align: center; text-align: center;\">\n<h1>\ ${title}</h1><table cellspacing=\"50\" align=\"center\"><tbody>\n";# generate linesfor f in $files; do filebase=${f%%.*}; # open new row if [[ $count == 0 ]]; then add_to_buffer "<tr>\n"; fi; create_line $f $filebase; # incr. counter if [[ $count == $row_end ]]; then add_to_buffer "</tr>\n"; count=0; else count=`expr $count + 1`; fi;done# add closing </tr> if missingif [[ $count < $row_end ]]; then add_to_buffer "</tr>\n";fi;# close tableadd_to_buffer "<tbody></table>\n</div>\n";# output header, table contents, and footerwrite "writing file $file_index";echo -e "$html_header" "$html_buffer" "$html_footer" > "$file_index";exit 0;