genwebgallery
view genwebgallery @ 17:87296564acd3
better depends in debian/control
author | meillo@marmaro.de |
---|---|
date | Sat, 10 May 2008 21:43:12 +0200 |
parents | 326bcd4e1708 |
children | 7f3cea97b789 |
line source
1 #!/bin/sh
2 #
3 # generates a web gallery
4 # requires: ImageMagick (convert)
5 #
6 # meillo@marmaro.de
7 #
10 PROGRAM=genwebgallery
11 VERSION=0.5
13 verbose="no"
14 targetDir="webgallery"
15 overwrite="no"
16 index="index.html"
17 sizePic=800
18 sizeThumb=150
19 galleryTitle=""
20 copyright=""
25 checkCreateDir() {
26 remove="no"
27 if [ -e "$targetDir" ] ; then
28 if [ "$overwrite" = "no" ] ; then
29 echo "output directory '$targetDir' already exists."
30 printf "remove it? [y/n] "
31 read remove
32 fi
34 if [ "$remove" = "y" -o "$overwrite" = "yes" ] ; then
35 echo "removing '$targetDir' ..."
36 rm -r "$targetDir"
37 if [ $? -ne 0 ] ; then
38 echo "ABORT"
39 exit 4
40 fi
41 else
42 echo "keep output directory"
43 echo "ABORT"
44 exit 3
45 fi
46 fi
48 mkdir -p "$targetDir"
49 }
54 insertHeader() {
55 echo "
56 <?xml version=\"1.0\" encoding=\"utf-8\"?>
57 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"
58 \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">
59 <html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">
60 <head>
61 <title>$titleName</title>
62 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
63 <meta name=\"Generator\" content=\"genwebgallery - http://prog.marmaro.de\" />
64 </head>
65 <body>
67 "
68 }
72 insertFooter() {
73 echo "
75 </body>
76 </html>
77 "
78 }
82 log() {
83 if [ $verbose = "yes" ] ; then
84 echo "$1";
85 fi
86 }
90 checkConvert() {
91 log "checking convert installation"
92 if [ ! `command -v convert` ] ; 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 usage() {
104 echo "usage: $PROGRAM [OPTIONS] PICTURES"
105 exit 1
106 }
110 help() {
111 echo "$PROGRAM
113 generates a web gallery consisting of html pages
115 usage: $PROGRAM [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 pictures ($sizePic)
126 -ts PIXELS size of the thumbnails ($sizeThumb)
127 --overwrite overwrite output directory ($overwrite)
129 for more information see man page: $PROGRAM(1)
131 author: meillo@marmaro.de
132 homepage: http://prog.marmaro.de
133 "
134 exit 0
135 }
140 # option processing
142 while [ "$#" -ge 1 ] && [ `echo "$1" | awk '{print substr($0,1,1)}'` = '-' ] ; do
143 case $1 in
144 '--version')
145 echo "$PROGRAM 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: $PROGRAM --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"