genwebgallery

view genwebgallery @ 34:6a3ef869fd68

version 0.6
author meillo@marmaro.de
date Wed, 04 Jun 2008 23:02:30 +0200
parents 9fac7c9e2611
children 42bf012f6045
line source
1 #!/bin/sh
2 #
3 # generates a web gallery
4 # requires: ImageMagick (convert)
5 #
6 # meillo@marmaro.de
7 # http://prog.marmaro.de/genwebgallery
8 #
11 PROGRAM=genwebgallery
12 VERSION=0.6
14 verbose="no"
15 targetDir="webgallery"
16 overwrite="no"
17 index="index.html"
18 sizePic=800
19 sizeThumb=150
20 galleryTitle=""
21 footer=""
26 checkCreateDir() {
27 remove="no"
28 if [ -e "$targetDir" ] ; then
29 if [ "$overwrite" = "no" ] ; then
30 echo "output directory '$targetDir' already exists."
31 printf "remove it? [y/n] "
32 read remove
33 fi
35 if [ "$remove" = "y" -o "$overwrite" = "yes" ] ; then
36 echo "removing '$targetDir' ..."
37 rm -r "$targetDir"
38 if [ $? -ne 0 ] ; then
39 echo "ABORT"
40 exit 4
41 fi
42 else
43 echo "keep output directory"
44 echo "ABORT"
45 exit 3
46 fi
47 fi
49 mkdir -p "$targetDir"
50 }
55 insertHeader() {
56 echo "
57 <?xml version=\"1.0\" encoding=\"utf-8\"?>
58 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"
59 \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">
60 <html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">
61 <head>
62 <title>$titleName</title>
63 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
64 <meta name=\"Generator\" content=\"genwebgallery - http://prog.marmaro.de/genwebgallery\" />
65 </head>
66 <body>
68 "
69 }
73 insertFooter() {
74 echo "
76 </body>
77 </html>
78 "
79 }
83 log() {
84 if [ $verbose = "yes" ] ; then
85 echo "$1";
86 fi
87 }
91 checkConvert() {
92 log "checking convert installation"
93 if [ ! `command -v convert` ] ; then
94 echo "Can not find 'convert' (package imagemagick)"
95 echo "ABORT"
96 exit 2
97 fi
98 log "convert found:"
99 log "`convert -version`"
100 }
104 usage() {
105 echo "usage: $PROGRAM [OPTIONS] PICTURES"
106 exit 1
107 }
111 help() {
112 echo "$PROGRAM
114 generates a web gallery consisting of html pages
116 usage: $PROGRAM [OPTIONS] PICTURES
118 options:
119 --version print program version
120 --help display this output
121 -v be verbose ($verbose)
122 -o DIR folder where generated files go to ($targetDir)
123 -i FILE the name of the index file ($index)
124 -t TEXT title of the gallery ($galleryTitle)
125 -f TEXT footer text ($footer)
126 -ps PIXELS size of the pictures ($sizePic)
127 -ts PIXELS size of the thumbnails ($sizeThumb)
128 --overwrite overwrite output directory ($overwrite)
130 for more information see man page: $PROGRAM(1)
132 author: meillo@marmaro.de
133 homepage: http://prog.marmaro.de/genwebgallery
134 "
135 exit 0
136 }
141 # option processing
143 while [ "$#" -ge 1 ] && [ `echo "$1" | awk '{print substr($0,1,1)}'` = '-' ] ; do
144 case $1 in
145 '--version')
146 echo "$PROGRAM version $VERSION"
147 exit 0
148 ;;
149 '--help')
150 help
151 ;;
152 '-v' | '--verbose')
153 verbose="yes"
154 shift
155 ;;
156 '-o' | '--output')
157 targetDir="$2"
158 shift
159 shift
160 ;;
161 '-i' | '--index')
162 index=$2
163 shift
164 shift
165 ;;
166 '-t' | '--title')
167 galleryTitle="$2"
168 shift
169 shift
170 ;;
171 '-f' | '--footer')
172 footer=$2
173 shift
174 shift
175 ;;
176 '-ps' | '--pic-size')
177 sizePic=$2
178 shift
179 shift
180 ;;
181 '-ts' | '--thumb-size')
182 sizeThumb=$2
183 shift
184 shift
185 ;;
186 '--overwrite')
187 overwrite="yes"
188 shift
189 ;;
190 *)
191 echo "invalid option: $1"
192 echo "see: $PROGRAM --help"
193 exit 1
194 esac
196 done
198 if [ $# -eq 0 ] ; then
199 usage
200 fi
204 # verbose output
205 log "verbose: $verbose"
206 log
207 log "output dir: $targetDir"
208 log "index file: $index"
209 log "gallery title: $galleryTitle"
210 log "footer text: $footer"
211 log "picture size: ${sizePic}px"
212 log "thumbnail size: ${sizeThumb}px"
213 log "overwrite output dir: $overwrite"
214 log
215 checkConvert
216 log
220 # generate web gallery
222 checkCreateDir
224 echo `insertHeader` > "$targetDir/$index"
225 if [ "$galleryTitle" != "" ] ; then
226 echo "<h1>$galleryTitle</h1>" >> "$targetDir/$index"
227 fi
229 for i in "$@" ; do
230 file="`basename $i`"
231 targetFile="$targetDir/$file.htm"
232 log "processing file: $file"
234 # copy and resize pics
235 convert "$i" -resize ${sizePic}x${sizePic} "$targetDir/$file"
236 if [ $? -ne 0 ] ; then
237 log " skipping"
238 continue
239 fi
240 convert "$i" -resize ${sizeThumb}x${sizeThumb} "$targetDir/_$file"
242 # generate pic page
243 echo `insertHeader` > "$targetFile"
244 if [ "$galleryTitle" != "" ] ; then
245 echo "<h1>$galleryTitle</h1>" >> "$targetFile"
246 fi
247 echo "<p><a href=\"$index\"><img src=\"$file\" alt=\"$file\" /></a></p>" >> "$targetFile"
248 if [ "$footer" != "" ] ; then
249 echo "<p>$footer</p>" >> "$targetFile"
250 fi
251 echo `insertFooter` >> "$targetFile"
253 # generate content for index file
254 echo " <a href=\"$file.htm\"><img src=\"_$file\" alt=\"$file\" /></a>" >> "$targetDir/$index"
255 done
257 if [ "$footer" != "" ] ; then
258 echo "<p>$footer</p>" >> "$targetDir/$index"
259 fi
260 echo `insertFooter` >> "$targetDir/$index"