#!/bin/bash ###################################################################### # Albatross VERSION=0.26.0 # # Bash album scripter. Will automatically convert into, link and build # web paged with thumbnails and intermediate formats for viewing # digital photographs in a web page format for Internet or Intranet # purposes. # # Albatross was written completely by myself for my own purposes but # if someone else finds it useful I am all the happier. It is # implemented as a bash shell script and should run on most platforms # capable of simulating a reasonable unix environment. It has been # tested on several Linux distros plus Cygwin in windows and should # work fine. ###################################################################### ###################################################################### # IMPORTANT PLEASE READ BEFORE YOU WEEP # # ImageMagick may or may not be present on your system. Prior to using # this script you need to install at least the convert command from # this package that you may find here # http://www.imagemagick.org/script/index.php # # In order to use and extract the exif information, this code requires # jhead to be installed. It will look for jhead in the PATH of your # system. Please find it at http://www.sentex.net/~mwandel/jhead/ # ###################################################################### ###################################################################### # Standard configuration options, can be overridden with options workdir=".albatross" thumbnailsize="120x120" thumbnailquality="40" mediumsize="600x600" mediumquality="75" bgcolor="#000000" text="#ffff00" link="#ffff00" vlink="#a0a0a0" exifcolor="#909090" filetypes="jpg JPG gif GIF jpeg JPEG bmp BMP png PNG" columns="4" indexname="index.html" border="0" cellspacing="0" cellpadding="2" width="90%" align_thumb="center" captions="captions.txt" captionfontsize="-1" exifmedium="yes" recurse_directories="yes" dirtablewidth="90%" dirfontsize="+1" ###################################################################### ### NO USER MODIFIABLES BEYOND THIS POINT ###################################################################### ###################################################################### # Save the IFS in case we need to modify it OLDIFS="$IFS" ###################################################################### # Argument checking while [ $# -gt 0 ]; do # --columns if [ "$1" = "--columns" ]; then columns="$2" fi # --light if [ "$1" = "--light" ]; then bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" fi # --bgcolor if [ "$1" = "--bgcolor" ]; then bgcolor="$2" fi # --textcolor if [ "$1" = "--textcolor" ]; then text="$2" fi # --linkcolor if [ "$1" = "--linkcolor" ]; then link="$2" fi # --vlinkcolor if [ "$1" = "--vlinkcolor" ]; then vlink="$2" fi # --clear if [ "$1" = "--clear" ]; then IFS=$'\n' startdir=$PWD for recursedir in $(find -type d | grep -v "$workdir"); do echo "Cleaning: $recursedir" IFS=$OLDIFS cd "$startdir" cd "$recursedir" rm "$indexname" rm -rf "$workdir" done exit fi # --thumbnailsize if [ "$1" = "--thumbnailsize" ]; then thumbnailsize="$2" fi # --mediumsize if [ "$1" = "--mediumsize" ]; then mediumsize="$2" fi # --thumbnailquality if [ "$1" = "--thumbnailquality" ]; then thumbnailquality="$2" fi # --thumbnailquality if [ "$1" = "--mediumquality" ]; then mediumquality="$2" fi # --captions if [ "$1" = "--captions" ]; then gencaption="yes" touch "$captions" fi # --version if [ "$1" = "--version" ]; then echo " Albatross version $VERSION Written by Anders \"Ichimusai\" Pettersson http://www.ichimusai.org/albatross" fi shift done IFS=$'\n' startdir=$PWD for recursedir in $(find -type d | grep -v "$workdir"); do echo echo -n "Processing {$recursedir} " IFS=$OLDIFS cd "$startdir" cd "$recursedir" ###################################################################### # No more arguiments, let's go do it! listarguments="" for i in $filetypes; do listarguments="$listarguments *.$i" done # Width and Breatdh :-) width=`echo $mediumsize | awk -Fx {' print $1 '}` height=`echo $mediumsize | awk -Fx {' print $2 '}` # Create the workdir if it does not exist if [ ! -d "$workdir" ]; then mkdir "$workdir" fi # Find all filetypes ### UNGRACEFUL HANDLING OF SPACE IN FILE NAMES! filelist=`ls 2>/dev/null $listarguments` # Convert images into thumbnails and medium format pictures and # create the individual webpages for each image # Number of images number_of_images=`echo $filelist | wc | awk {' print $2 '}` counter="0" tempfile="/tmp/albatross.$RANDOM" touch tempfile for image in $filelist ; do counter=$(( $counter + 1 )) if [ "$counter" = "1" ]; then first=$image fi if [ "$counter" = "$number_of_images" ]; then last=$image fi done counter="0" next=$last for image in $filelist ; do counter=$(( $counter + 1 )) previous=$current current=$next next=$image if [ "$counter" = "$number_of_pictures" ]; then next=$first fi if [ "$counter" != "1" ]; then echo >>"$tempfile" "#$(( $counter - 1)):$previous:$current:$next" fi done previous="$current" current="$next" next="$first" counter=$(( $counter + 1 )) echo >>"$tempfile" "#$(( $counter - 1)):$previous:$current:$next" # For each of the images do the following counter="0" for image in $filelist ; do counter=$(( $counter + 1 )) previous=`grep \^\#$counter: $tempfile | awk -F: {' print $2 '}` next=`grep \^\#$counter: $tempfile | awk -F: {' print $4 '}` echo -n "[$image]" # Thumbnail conversion if [ ! -e "$workdir/thumb_$image" ]; then convert -quality "$thumbnailquality" -size "$thumbnailsize" \ -resize "$thumbnailsize" +profile "*" \ "$image" "$workdir/thumb_$image" echo -n "." fi # Medium size conversion if [ ! -e "$workdir/medium_$image" ]; then convert -quality "$mediumquality" -size "$mediumsize" -resize "$mediumsize" \ "$image" "$workdir/medium_$image" echo -n "*" fi # Create the web page for the medium format here if [ "$exifmedium" = "yes" ]; then exif=`jhead $image` else exif="" fi if [ -e "$captions" ]; then caption_long=`grep $image $captions | awk -F: '{ print $3 }'` caption_short=`grep $image $captions | awk -F: '{ print $2 }'` else caption_long="" caption_short="" fi echo >$workdir/$image.html " $image
Previous
Index
Next

$caption_short

$image


$caption_long
$exif
Back to Index
http://ichimusai.org/albatross
" echo -n "/" # Generate caption file if requested if [ "$gencaption" = "yes" ]; then # Check if there is already a line touch "$captions" entry=`grep $image $captions | awk -F: '{ print $1 }'` if [ "$entry" = "" ]; then echo >>"$captions" "$image::" fi fi done echo webname=`OLDIFS=$IFS; IFS=$'\n'; for i in $(echo $PWD | sed 's/\//\n/g');\ do test=$i ; done ; echo $i ; IFS=$OLDIFS` rm "$tempfile" # Remove the tempfile for the sorting of pictures # Create the web page echo >$indexname " $webname

$webname


" # Here goes the subdirectory informations #subdirs=`find ./ -type d | grep -v $workdir` IFS=$'\n' echo >>$indexname " <<< " tabcounter="0" for i in $( find -maxdepth 1 -type d | grep -v $workdir | sort ); do if [ "$tabcounter" -gt "$columns" ]; then echo >>$indexname " " tabcounter="0" fi tabcounter=$(( $tabcounter + 1 )) echo >>$indexname " " done echo >>$indexname "
$i

" # Get the name for this directory if [ -e "$captions" ]; then dirname=`grep "dir" $captions | awk -F: {' print $2 '}` direxplanation=`grep "dir" $captions | awk -F: {' print $3 '}` echo >>$indexname "

$dirname

$direxplanation
" fi IFS=$OLDIFS # Set up the table head echo >>$indexname " " # For each of the images columncount="0" for image in $filelist; do caption=`grep 2>/dev/null $image $captions | awk -F: '{ print $2 }'` echo >>$indexname "" columncount=$(($columncount+1)) if [ "$columncount" == "$columns" ]; then echo >>$indexname "" columncount="0" fi done # Close the table and HTML file echo >>$indexname "
$image

$caption

Made by Albatross $VERSION
http://ichimusai.org/albatross
" done # All dirs done