genwebgallery

view genwebgallery @ 6:cb0dff8c48c6

added option --overwrite; refactored checkCreateDir; fixed HTML output; introduced exit code 3 and 4; better help output
author meillo@marmaro.de
date Fri, 23 Nov 2007 22:43:41 +0100
parents abe1e48e0708
children 6273a788c4fd
line source
1 #!/bin/sh
2 #
3 # generates a web gallery
4 # requires: ImageMagick (convert)
5 #
6 # meillo@marmaro.de
7 #
10 VERSION=0.4
12 verbose="no"
13 targetDir="webgallery"
14 overwrite="no"
15 index="index.html"
16 sizePic=800
17 sizeThumb=150
18 galleryTitle="photo gallery"
19 copyright=""
24 function checkCreateDir() {
25 remove="no"
26 if [ -e "$targetDir" ] ; then
27 if [ "$overwrite" = "no" ] ; then
28 echo "output directory '$targetDir' already exists."
29 echo -n "remove it? [y/n] "
30 read remove
31 fi
33 if [ "$remove" = "y" -o "$overwrite" = "yes" ] ; then
34 echo "removing '$targetDir' ..."
35 rm -r "$targetDir"
36 if [ $? -ne 0 ] ; then
37 echo "ABORT"
38 exit 4
39 fi
40 else
41 echo "keep output directory"
42 echo "ABORT"
43 exit 3
44 fi
45 fi
47 mkdir -p "$targetDir"
48 }
53 function insertHeader() {
54 echo "
55 <?xml version=\"1.0\" encoding=\"utf-8\"?>
56 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"
57 \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">
58 <html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">
59 <head>
60 <title>$titleName</title>
61 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
62 <meta name=\"Generator\" content=\"genwebgallery - http://prog.marmaro.de\" />
63 </head>
64 <body>
66 "
67 }
71 function insertFooter() {
72 echo "
74 </body>
75 </html>
76 "
77 }
81 function log() {
82 if [ $verbose = "yes" ] ; then
83 echo "$1";
84 fi
85 }
89 function checkConvert() {
90 log "checking convert installation"
91 (convert -version) 2> /dev/null > /dev/null
92 if [ $? -ne 0 ] ; then
93 echo "Can not find 'convert' (package imagemagick)"
94 echo "ABORT"
95 exit 2
96 fi
97 log "convert found:"
98 log "`convert -version`"
99 }
103 function usage() {
104 echo "usage: `basename $0` [OPTIONS] FILES"
105 exit 1
106 }
110 function help() {
111 echo "`basename $0`
113 generates a web gallery consisting of html pages
115 usage: `basename $0` [OPTIONS] PICTURES
117 options:
118 --version print program version
119 --help display this output
120 -v be verbose ($verbose)
121 -o DIR folder where generated files go to ($targetDir)
122 -i FILE the name of the index file ($index)
123 -t TEXT title of the gallery ($galleryTitle)
124 -c TEXT a copyright notice ($copyright)
125 -ps PIXELS size of the pics ($sizePic)
126 -ts PIXELS size of the thumbnails ($sizeThumb)
127 --overwrite overwrite output directory ($overwrite)
129 for more information see man page: genwebgallery(1)
131 author: meillo@marmaro.de
132 homepage: http://prog.marmaro.de
133 "
134 exit 0
135 }
140 # option processing
142 while [ "$#" -ge 1 -a "${1:0:1}" = '-' ] ; do
143 case $1 in
144 '--version')
145 echo "genwebgallery version $VERSION"
146 exit 0
147 ;;
148 '--help')
149 help
150 ;;
151 '-v' | '--verbose')
152 verbose="yes"
153 shift
154 ;;
155 '-o' | '--output')
156 targetDir="$2"
157 shift
158 shift
159 ;;
160 '-i' | '--index')
161 index=$2
162 shift
163 shift
164 ;;
165 '-t' | '--title')
166 galleryTitle="$2"
167 shift
168 shift
169 ;;
170 '-c' | '--copyright')
171 copyright=$2
172 shift
173 shift
174 ;;
175 '-ps' | '--pic-size')
176 sizePic=$2
177 shift
178 shift
179 ;;
180 '-ts' | '--thumb-size')
181 sizeThumb=$2
182 shift
183 shift
184 ;;
185 '--overwrite')
186 overwrite="yes"
187 shift
188 ;;
189 *)
190 echo "invalid option: $1"
191 echo "see: `basename $0` --help"
192 exit 1
193 esac
195 done
197 if [ $# -eq 0 ] ; then
198 usage
199 fi
203 # verbose output
204 log "verbose: $verbose"
205 log
206 log "output dir: $targetDir"
207 log "index file: $index"
208 log "gallery title: $galleryTitle"
209 log "copyright notice: $copyright"
210 log "picture size: ${sizePic}px"
211 log "thumbnail size: ${sizeThumb}px"
212 log "overwrite output dir: $overwrite"
213 log
214 checkConvert
215 log
219 # generate web gallery
221 checkCreateDir
223 echo `insertHeader` > "$targetDir/$index"
224 if [ "$galleryTitle" != "" ] ; then
225 echo "<h1>$galleryTitle</h1>" >> "$targetDir/$index"
226 fi
228 for i in "$@" ; do
229 file="`basename $i`"
230 targetFile="$targetDir/$file.htm"
231 log "processing file: $file"
233 # generate pic page
234 echo `insertHeader` > "$targetFile"
235 if [ "$galleryTitle" != "" ] ; then
236 echo "<h1>$galleryTitle</h1>" >> "$targetFile"
237 fi
238 echo "<p><a href=\"$index\"><img src=\"$file\" alt=\"$file\" /></a></p>" >> "$targetFile"
239 if [ "$copyright" != "" ] ; then
240 echo "<p>$copyright</p>" >> "$targetFile"
241 fi
242 echo `insertFooter` >> "$targetFile"
244 # copy and resize pics
245 convert "$i" -resize ${sizePic}x${sizePic} "$targetDir/$file"
246 convert "$i" -resize ${sizeThumb}x${sizeThumb} "$targetDir/_$file"
248 # generate content for index file
249 echo " <a href=\"$file.htm\"><img src=\"_$file\" alt=\"$file\" /></a>" >> "$targetDir/$index"
250 done
252 if [ "$copyright" != "" ] ; then
253 echo "<p>$copyright</p>" >> "$targetDir/$index"
254 fi
255 echo `insertFooter` >> "$targetDir/$index"