view genwebgallery @ 12:27f96c3b8224 deb_0.4-2

fixed hyphen-minus-conflict in man page; refactored debian/rules (removed a lot)
author meillo@marmaro.de
date Sat, 24 Nov 2007 23:29:16 +0100
parents cb0dff8c48c6
children 6273a788c4fd
line wrap: on
line source

#!/bin/sh
#
# generates a web gallery
# requires: ImageMagick (convert)
#
# meillo@marmaro.de
#


VERSION=0.4

verbose="no"
targetDir="webgallery"
overwrite="no"
index="index.html"
sizePic=800
sizeThumb=150
galleryTitle="photo gallery"
copyright=""




function checkCreateDir() {
	remove="no"
	if [ -e "$targetDir" ] ; then
		if [ "$overwrite" = "no" ] ; then
			echo "output directory '$targetDir' already exists."
			echo -n "remove it? [y/n] "
			read remove
		fi

		if [ "$remove" = "y" -o "$overwrite" = "yes" ] ; then
			echo "removing '$targetDir' ..."
			rm -r "$targetDir"
			if [ $? -ne 0 ] ; then
				echo "ABORT"
				exit 4
			fi
		else
			echo "keep output directory"
			echo "ABORT"
			exit 3
		fi
	fi

	mkdir -p "$targetDir"
}




function insertHeader() {
  echo "
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"
  \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">
<head>
<title>$titleName</title>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
  <meta name=\"Generator\" content=\"genwebgallery - http://prog.marmaro.de\" />
</head>
<body>

"
}



function insertFooter() {
	echo "

</body>
</html>
"
}



function log() {
	if [ $verbose = "yes" ] ; then
		echo "$1";
	fi
}



function checkConvert() {
	log "checking convert installation"
	(convert -version) 2> /dev/null > /dev/null
	if [ $? -ne 0 ] ; then
		echo "Can not find 'convert' (package imagemagick)"
		echo "ABORT"
		exit 2
	fi
	log "convert found:"
	log "`convert -version`"
}



function usage() {
	echo "usage: `basename $0` [OPTIONS] FILES"
	exit 1
}



function help() {
	echo "`basename $0`

generates a web gallery consisting of html pages

usage: `basename $0` [OPTIONS] PICTURES

options:
	--version   print program version
	--help      display this output
	-v          be verbose ($verbose)
	-o DIR      folder where generated files go to ($targetDir)
	-i FILE     the name of the index file ($index)
	-t TEXT     title of the gallery ($galleryTitle)
	-c TEXT     a copyright notice ($copyright)
	-ps PIXELS  size of the pics ($sizePic)
	-ts PIXELS  size of the thumbnails ($sizeThumb)
	--overwrite overwrite output directory ($overwrite)

for more information see man page: genwebgallery(1)

author: meillo@marmaro.de
homepage: http://prog.marmaro.de
"
	exit 0
}




# option processing

while [  "$#" -ge 1  -a  "${1:0:1}" = '-'  ] ; do
	case $1 in
		'--version')
			echo "genwebgallery version $VERSION"
			exit 0
			;;
		'--help')
			help
			;;
		'-v' | '--verbose')
			verbose="yes"
			shift
			;;
		'-o' | '--output')
			targetDir="$2"
			shift
			shift
			;;
		'-i' | '--index')
			index=$2
			shift
			shift
			;;
		'-t' | '--title')
			galleryTitle="$2"
			shift
			shift
			;;
		'-c' | '--copyright')
			copyright=$2
			shift
			shift
			;;
		'-ps' | '--pic-size')
			sizePic=$2
			shift
			shift
			;;
		'-ts' | '--thumb-size')
			sizeThumb=$2
			shift
			shift
			;;
		'--overwrite')
			overwrite="yes"
			shift
			;;
		*)
			echo "invalid option: $1"
			echo "see: `basename $0` --help"
			exit 1
	esac

done

if [ $# -eq 0 ] ; then
	usage
fi



# verbose output
log "verbose:              $verbose"
log
log "output dir:           $targetDir"
log "index file:           $index"
log "gallery title:        $galleryTitle"
log "copyright notice:     $copyright"
log "picture size:         ${sizePic}px"
log "thumbnail size:       ${sizeThumb}px"
log "overwrite output dir: $overwrite"
log
checkConvert
log



# generate web gallery

checkCreateDir

echo `insertHeader` > "$targetDir/$index"
if [ "$galleryTitle" != "" ] ; then
	echo "<h1>$galleryTitle</h1>" >> "$targetDir/$index"
fi

for i in "$@" ; do
	file="`basename $i`"
	targetFile="$targetDir/$file.htm"
	log "processing file: $file"

	# generate pic page
	echo `insertHeader` > "$targetFile"
	if [ "$galleryTitle" != "" ] ; then
		echo "<h1>$galleryTitle</h1>" >> "$targetFile"
	fi
	echo "<p><a href=\"$index\"><img src=\"$file\" alt=\"$file\" /></a></p>" >> "$targetFile"
	if [ "$copyright" != "" ] ; then
		echo "<p>$copyright</p>" >> "$targetFile"
	fi
	echo `insertFooter` >> "$targetFile"

	# copy and resize pics
	convert "$i" -resize ${sizePic}x${sizePic} "$targetDir/$file"
	convert "$i" -resize ${sizeThumb}x${sizeThumb} "$targetDir/_$file"

	# generate content for index file
	echo "    <a href=\"$file.htm\"><img src=\"_$file\" alt=\"$file\" /></a>" >> "$targetDir/$index"
done

if [ "$copyright" != "" ] ; then
	echo "<p>$copyright</p>" >> "$targetDir/$index"
fi
echo `insertFooter` >> "$targetDir/$index"