#!/bin/bash # $Id: make-gallery.sh,v 1.1 2005/08/25 14:13:56 spliffy Exp $ # Globals export 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 options export 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/null do 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;; esac done if [[ ! -z $1 ]]; then shift $OPTIND-1; fi if [[ ! -z $1 ]]; then file_index="$1"; fi; # html template html_buffer=""; if [[ -z $generated ]]; then generated=`date`; fi; if [[ -z $html_header ]]; then # html_header="\n\n${title}\n\n"; html_header=`cat << EOT ${title} EOT` fi; if [[ -z $html_footer ]]; then html_footer="\n" fi; # image sizes export size="${height}x$width"; export normal_size="${normal_width}x${normal_height}"; # output text function write { echo $1; } # create thumbnails function 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 output function add_to_buffer { html_buffer="${html_buffer}$1"; } function create_line { jpeg="$1"; basename="$2"; img="\"$jpeg\""; # href="${file_image}?${jpeg}"; href="pages/${jpeg}.html"; link="$img"; add_to_buffer "$link

${jpeg}

\n"; } function create_navfile { a=`cat << EOT ${1}
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 ${title}
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 ${2}

${2}

« Back  Übersicht  Next »


$2


« Back  Übersicht  Next »
EOT` echo "$a" > "pages/${2}.html"; } #create_navfile; create_thumbnails; create_normal; create_pages; # files files=`ls *.jpg`; count=0; row_end=`expr $rows - 1`; add_to_buffer "
\n

\ ${title}

\n"; # generate lines for f in $files; do filebase=${f%%.*}; # open new row if [[ $count == 0 ]]; then add_to_buffer "\n"; fi; create_line $f $filebase; # incr. counter if [[ $count == $row_end ]]; then add_to_buffer "\n"; count=0; else count=`expr $count + 1`; fi; done # add closing if missing if [[ $count < $row_end ]]; then add_to_buffer "\n"; fi; # close table add_to_buffer "
\n
\n"; # output header, table contents, and footer write "writing file $file_index"; echo -e "$html_header" "$html_buffer" "$html_footer" > "$file_index"; exit 0;