genwebgallery

view genwebgallery @ 2:abe1e48e0708

CHANGELOG gets generated now; reviewed Makefile
author meillo@marmaro.de
date Thu, 22 Nov 2007 21:36:20 +0100
parents 9f4fa0bc1584
children cb0dff8c48c6
line source
1 #!/bin/sh
2 #
3 # generates a web gallery of static web pages
4 # requires: ImageMagick (convert)
5 #
6 # meillo@marmaro.de
7 #
10 VERSION=0.3
12 targetDir="web"
13 index="index.htm"
14 sizePic=640
15 sizeThumb=200
16 galleryTitle="gallery title"
17 copyright="please mind the copyright"
19 verbose=""
22 function checkCreateDir() {
23 if [ -d "$targetDir" ] ; then
24 echo "Target dir '$targetDir' already exists."
25 echo -n "remove it? [y/n] "
27 read remove
28 if [ $remove = "y" ] ; then
29 rm -r "$targetDir"
30 echo "removing '$targetDir' ..."
31 else
32 exit 1
33 fi
34 fi
35 mkdir -p "$targetDir"
36 }
40 function insertHeader() {
41 echo <<EOF
42 <?xml version="1.0" encoding="utf-8"?>
43 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
44 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
45 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
46 <head>
47 <title>$titleName</title>
48 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
49 <meta name="Generator" content="genwebgallery - see http://prog.marmaro.de" />
50 </head>
51 <body>
53 EOF
54 }
57 function insertFooter() {
58 echo <<EOF
60 </body>
61 </html>
62 EOF
63 }
66 function log() {
67 if [ $verbose ] ; then
68 echo "$1";
69 fi
70 }
73 function checkConvert() {
74 log "checking convert installation"
75 (convert -version) 2> /dev/null > /dev/null
76 if [ $? -ne 0 ] ; then
77 echo "Error: Can not find 'convert' (package imagemagick)"
78 echo "ABORT!"
79 exit 2
80 fi
81 log "`convert -version`"
82 }
85 ####
89 if [ $# -eq 0 ] ; then
90 echo "usage: `basename $0` [OPTIONS] FILES"
91 exit 0
92 fi
95 while [ "$#" -ge 1 -a "${1:0:1}" = '-' ] ; do
96 case $1 in
97 '--version')
98 echo "genwebgallery version $VERSION"
99 exit 0
100 ;;
101 '--help')
102 echo "`basename $0`
104 generates a web gallery consisting of html pages
106 usage: `basename $0` [OPTIONS] FILES
108 options:
109 --version: echo program version
110 --help: display this output
111 -v: be verbose
112 -o DIR: all generated content is copied to this folder
113 -i FILE: the name of the index file (index.htm)
114 -t TITLE: title of the gallery
115 -c COPYRIGHT: a copyright notice
116 -ps PIXELS: size of the pics
117 -ts PIXELS: size of the thumbnails
119 author: meillo@marmaro.de
120 homepage: http://prog.marmaro.de
121 "
122 exit 0
123 ;;
124 '-v' | '--verbose')
125 verbose=1
126 shift
127 ;;
128 '-o' | '--output')
129 targetDir=$2
130 shift
131 shift
132 ;;
133 '-i' | '--index')
134 index=$2
135 shift
136 shift
137 ;;
138 '-t' | '--title')
139 galleryTitle=$2
140 shift
141 shift
142 ;;
143 '-c' | '--copyright')
144 copyright=$2
145 shift
146 shift
147 ;;
148 '-ps' | '--pic-size')
149 sizePic=$2
150 shift
151 shift
152 ;;
153 '-ts' | '--thumb-size')
154 sizeThumb=$2
155 shift
156 shift
157 ;;
158 *)
159 echo "invalid option: $1"
160 echo "see: `basename $0` --help"
161 exit 1
162 esac
164 done
166 if [ $# -eq 0 ] ; then
167 echo "usage: `basename $0` [OPTIONS] FILES"
168 exit 0
169 fi
172 # verbose output
173 log "verbose on"
174 log "output dir is: $targetDir"
175 log "index file is: $index"
176 log "gallery title is: $galleryTitle"
177 log "copyright notice is: $copyright"
178 log "picture size is: $sizePic"
179 log "thumbnail size is: $sizeThumb"
180 checkConvert
181 log ""
184 checkCreateDir
186 insertHeader > "$targetDir/$index"
187 echo "<h1>$galleryTitle</h1>" >> "$targetDir/$index"
189 for i in "$@" ; do
190 file=`basename $i`
191 targetFile="$targetDir/$file.htm"
192 log "processing file: $file"
194 # generate pic page
195 insertHeader > "$targetFile"
196 echo "<h1>$galleryTitle</h1>" \
197 "<p><a href=\"$index\"><img src=\"$file\" alt=\"$file\" /></a></p>" \
198 "<p>$copyright</p>" >> "$targetFile"
199 insertFooter >> "$targetFile"
201 # copy and resize pics
202 convert "$i" -resize ${sizePic}x${sizePic} "$targetDir/$file"
203 convert "$i" -resize ${sizeThumb}x${sizeThumb} "$targetDir/_$file"
205 # generate content for index file
206 echo " <a href=\"$file.htm\"><img src=\"_$file\" alt=\"$file\" /></a>" >> "$targetDir/$index"
207 done
209 echo "<p>$copyright</p>" >> "$targetDir/$index"
210 insertFooter >> "$targetDir/$index"