genwebgallery

view genwebgallery @ 0:9f4fa0bc1584

initial commit
author meillo@marmaro.de
date Thu, 22 Nov 2007 21:13:25 +0100
parents
children abe1e48e0708
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 targetDir="web"
11 index="index.htm"
12 sizePic=640
13 sizeThumb=200
14 galleryTitle="gallery title"
15 copyright="please mind the copyright"
17 verbose=""
20 function checkCreateDir() {
21 if [ -d "$targetDir" ] ; then
22 echo "Target dir '$targetDir' already exists."
23 echo -n "remove it? [y/n] "
25 read remove
26 if [ $remove = "y" ] ; then
27 rm -r "$targetDir"
28 echo "removing '$targetDir' ..."
29 else
30 exit 1
31 fi
32 fi
33 mkdir -p "$targetDir"
34 }
38 function insertHeader() {
39 echo <<EOF
40 <?xml version="1.0" encoding="utf-8"?>
41 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
42 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
43 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
44 <head>
45 <title>$titleName</title>
46 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
47 <meta name="Generator" content="genwebgallery - see http://prog.marmaro.de" />
48 </head>
49 <body>
51 EOF
52 }
55 function insertFooter() {
56 echo <<EOF
58 </body>
59 </html>
60 EOF
61 }
64 function log() {
65 if [ $verbose ] ; then
66 echo "$1";
67 fi
68 }
71 function checkConvert() {
72 log "checking convert installation"
73 (convert -version) 2> /dev/null > /dev/null
74 if [ $? -ne 0 ] ; then
75 echo "Error: Can not find 'convert' (package imagemagick)"
76 echo "ABORT!"
77 exit 2
78 fi
79 log "`convert -version`"
80 }
83 ####
87 if [ $# -eq 0 ] ; then
88 echo "usage: `basename $0` [OPTIONS] FILES"
89 exit 0
90 fi
93 while [ "$#" -ge 1 -a "${1:0:1}" = '-' ] ; do
94 case $1 in
95 '--version')
96 echo "genwebgallery version 0.3"
97 exit 0
98 ;;
99 '--help')
100 echo "`basename $0`
102 generates a web gallery consisting of html pages
104 usage: `basename $0` [OPTIONS] FILES
106 options:
107 --version: echo program version
108 --help: display this output
109 -v: be verbose
110 -o DIR: all generated content is copied to this folder
111 -i FILE: the name of the index file (index.htm)
112 -t TITLE: title of the gallery
113 -c COPYRIGHT: a copyright notice
114 -ps PIXELS: size of the pics
115 -ts PIXELS: size of the thumbnails
117 author: meillo@marmaro.de
118 homepage: http://prog.marmaro.de
119 "
120 exit 0
121 ;;
122 '-v' | '--verbose')
123 verbose=1
124 shift
125 ;;
126 '-o' | '--output')
127 targetDir=$2
128 shift
129 shift
130 ;;
131 '-i' | '--index')
132 index=$2
133 shift
134 shift
135 ;;
136 '-t' | '--title')
137 galleryTitle=$2
138 shift
139 shift
140 ;;
141 '-c' | '--copyright')
142 copyright=$2
143 shift
144 shift
145 ;;
146 '-ps' | '--pic-size')
147 sizePic=$2
148 shift
149 shift
150 ;;
151 '-ts' | '--thumb-size')
152 sizeThumb=$2
153 shift
154 shift
155 ;;
156 *)
157 echo "invalid option: $1"
158 echo "see: `basename $0` --help"
159 exit 1
160 esac
162 done
164 if [ $# -eq 0 ] ; then
165 echo "usage: `basename $0` [OPTIONS] FILES"
166 exit 0
167 fi
170 # verbose output
171 log "verbose on"
172 log "output dir is: $targetDir"
173 log "index file is: $index"
174 log "gallery title is: $galleryTitle"
175 log "copyright notice is: $copyright"
176 log "picture size is: $sizePic"
177 log "thumbnail size is: $sizeThumb"
178 checkConvert
179 log ""
182 checkCreateDir
184 insertHeader > "$targetDir/$index"
185 echo "<h1>$galleryTitle</h1>" >> "$targetDir/$index"
187 for i in "$@" ; do
188 file=`basename $i`
189 targetFile="$targetDir/$file.htm"
190 log "processing file: $file"
192 # generate pic page
193 insertHeader > "$targetFile"
194 echo "<h1>$galleryTitle</h1>" \
195 "<p><a href=\"$index\"><img src=\"$file\" alt=\"$file\" /></a></p>" \
196 "<p>$copyright</p>" >> "$targetFile"
197 insertFooter >> "$targetFile"
199 # copy and resize pics
200 convert "$i" -resize ${sizePic}x${sizePic} "$targetDir/$file"
201 convert "$i" -resize ${sizeThumb}x${sizeThumb} "$targetDir/_$file"
203 # generate content for index file
204 echo " <a href=\"$file.htm\"><img src=\"_$file\" alt=\"$file\" /></a>" >> "$targetDir/$index"
205 done
207 echo "<p>$copyright</p>" >> "$targetDir/$index"
208 insertFooter >> "$targetDir/$index"