#!/bin/bash # # easygg # v0.3, February 2004 # # easyGG is an automatic gallery generator. # Execute in a directory with Jpeg files. # The script requires the tools convert from ImageMagick and jhead. # # Copyright (c) 2003, 2004 Stephan Uhlmann # # /************************************************************************ # * This program is free software; you can redistribute it and/or modify * # * it under the terms of the GNU General Public License as published by * # * the Free Software Foundation; either version 2 of the License, or * # * (at your option) any later version. * # * * # * See http://www.fsf.org/copyleft/gpl.txt for the full text of the GPL. * # ************************************************************************/ # # Parameters (change them if you like) # Tools needed # specify full path when not in $PATH JHEAD="jhead" CONVERT="convert" MKDIR="mkdir" FIND="find" GREP="grep" SED="sed" BASENAME="basename" DU="du" SORT="sort" # title of each page TITLE=`$BASENAME \`pwd\`` # 0=debug,1=info,2=error,3=critical VERBOSELEVEL=1 # working directory # all files will be put in a subdirectory of this name SUBDIR="easygg" # Functions # $1 file htmlclear() { msg 0 "Creating HTML file for $1." echo -n > "$SUBDIR/$1.html" || msg 3 "Error creating HTML file. Stop." } # $1 string, $2 file htmlprint() { echo -e -n $1 >> "$SUBDIR/$2.html" || msg 3 "Error writing HTML file. Stop." } # $1 title, $2 file htmlheader() { msg 0 "Writing HTML header for $2." htmlprint "\n" $2 htmlprint "\n" $2 htmlprint "\n" $2 htmlprint "\n" $2 htmlprint "$1\n" $2 htmlprint "\n" $2 htmlprint "\n" $2 } # $1 file htmlfooter() { msg 0 "Writing HTML footer for $1." htmlprint "
\n" $1 htmlprint "Generated by easyGG
\n" $1 htmlprint "\n" $1 htmlprint "\n" $1 } # $1 severity, $2 message # | # `-> 0=debug,1=info,2=error,3=critical msg() { if [ $1 -ge $VERBOSELEVEL ]; then echo $2; fi if [ $1 -ge 3 ]; then exit; fi } # $1 tool toolcheck() { X=`type -p $1` if test $X && test -x $X; then return 0 else return 1 fi } # Main # All tools there? toolcheck $JHEAD || msg 3 "jhead not found." toolcheck $CONVERT || msg 3 "convert not found." toolcheck $MKDIR || msg 3 "mkdir not found." toolcheck $FIND || msg 3 "find not found." toolcheck $GREP || msg 3 "grep not found." toolcheck $SED || msg 3 "sed not found." toolcheck $BASENAME || msg 3 "basename not found." toolcheck $DU || msg 3 "du not found." toolcheck $SORT || msg 3 "sort not found." $MKDIR -p $SUBDIR || msg 3 "Error creating subdirectory. Stop." htmlclear index htmlheader $TITLE index htmlprint "

$TITLE

\n" index htmlprint "
\n" index htmlprint "\n" index htmlprint "\n" index X=$IFS IFS=$'\n' FILES=(`$FIND . -iregex ".*\.jpe?g$" -type f -maxdepth 1 -print | $SORT -f`) IFS=$X if [ ${#FILES[@]} -gt 0 ]; then msg 1 "Found ${#FILES[@]} image files." else msg 3 "No image files found. Stop." fi # need to precompute filenames because they are referenced back/ahead in the prev/next links for (( i=0; i < ${#FILES[@]}; i++ )); do FILENAMES[$i]=`$BASENAME "${FILES[$i]}" | $SED s/\ /_/g`; done for (( i=0; i < ${#FILES[@]}; i++ )) do FILE="${FILES[$i]}" FILENAME="${FILENAMES[$i]}" msg 1 "$(($i+1))/${#FILES[@]} $FILE" htmlprint "\n" index if [ $((i%5)) -eq 4 ]; then if [ $i -eq ${#FILES[@]} ]; then htmlprint "\n" index else htmlprint "\n\n" index fi fi done htmlprint "
" index CONVERT_OPTIONS="+profile APP1 -border 2x2 -bordercolor #000000" # look in exif if image needs rotation ORIENTATION=`$JHEAD "$FILE" | $GREP "Orientation"` if [ "$ORIENTATION" ]; then X=`echo $ORIENTATION | $SED s/.*rotate\ //` CONVERT_OPTIONS="$CONVERT_OPTIONS -rotate $X" fi $CONVERT $CONVERT_OPTIONS -scale "160x160 >" "$FILE" "$SUBDIR/thumb_$FILENAME" $CONVERT $CONVERT_OPTIONS -scale "640x640 >" "$FILE" "$SUBDIR/slide_$FILENAME" htmlprint "\"$FILENAME\"
" index htmlprint "$FILENAME" index # generate sub-pages htmlclear "page_$FILENAME" htmlheader "$TITLE" "page_$FILENAME" htmlprint "

$TITLE

\n" "page_$FILENAME" htmlprint "
\n" "page_$FILENAME" # navigation htmlprint "" "page_$FILENAME" if [ $i -gt 0 ]; then htmlprint "<-- prev" "page_$FILENAME" else htmlprint "        " "page_$FILENAME" fi htmlprint "  " "page_$FILENAME" htmlprint "^^index^^" "page_$FILENAME" htmlprint "  " "page_$FILENAME" if [ $((i+1)) -lt ${#FILES[@]} ]; then htmlprint "next -->\n" "page_$FILENAME" else htmlprint "        \n" "page_$FILENAME" fi htmlprint "" "page_$FILENAME" # table with image and info htmlprint "\n\n" "page_$FILENAME" htmlprint "\n" "page_$FILENAME" htmlprint "\n\n\n\n\n
\"$FILENAME\"
" "page_$FILENAME" INFOS1=(`$DU -k "$SUBDIR/slide_$FILENAME"`) INFOS2=`$JHEAD "$FILE" | $GREP -e "Date/Time"` htmlprint "File : $FILENAME ($((i+1))/${#FILES[@]})
Size : ${INFOS1[0]} KB
$INFOS2
" "page_$FILENAME" INFOS3=`$JHEAD "$FILE" | $GREP -e "Flash" -e "Focal length" -e "Exposure time" -e "Aperture" | $SED s/$/\/g` htmlprint "$INFOS3" "page_$FILENAME" htmlprint "
\n" "page_$FILENAME" htmlprint "
\n

\n" "page_$FILENAME" htmlfooter "page_$FILENAME" htmlprint "
\n" index htmlprint "


\n" index htmlfooter index