genwebgallery
diff genwebgallery @ 0:9f4fa0bc1584
initial commit
author | meillo@marmaro.de |
---|---|
date | Thu, 22 Nov 2007 21:13:25 +0100 |
parents | |
children | abe1e48e0708 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/genwebgallery Thu Nov 22 21:13:25 2007 +0100 1.3 @@ -0,0 +1,208 @@ 1.4 +#!/bin/sh 1.5 +# 1.6 +# generates a web gallery of static web pages 1.7 +# requires: ImageMagick (convert) 1.8 +# 1.9 +# meillo@marmaro.de 1.10 +# 1.11 + 1.12 + 1.13 +targetDir="web" 1.14 +index="index.htm" 1.15 +sizePic=640 1.16 +sizeThumb=200 1.17 +galleryTitle="gallery title" 1.18 +copyright="please mind the copyright" 1.19 + 1.20 +verbose="" 1.21 + 1.22 + 1.23 +function checkCreateDir() { 1.24 + if [ -d "$targetDir" ] ; then 1.25 + echo "Target dir '$targetDir' already exists." 1.26 + echo -n "remove it? [y/n] " 1.27 + 1.28 + read remove 1.29 + if [ $remove = "y" ] ; then 1.30 + rm -r "$targetDir" 1.31 + echo "removing '$targetDir' ..." 1.32 + else 1.33 + exit 1 1.34 + fi 1.35 + fi 1.36 + mkdir -p "$targetDir" 1.37 +} 1.38 + 1.39 + 1.40 + 1.41 +function insertHeader() { 1.42 + echo <<EOF 1.43 +<?xml version="1.0" encoding="utf-8"?> 1.44 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 1.45 + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 1.46 +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> 1.47 +<head> 1.48 +<title>$titleName</title> 1.49 +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 1.50 + <meta name="Generator" content="genwebgallery - see http://prog.marmaro.de" /> 1.51 +</head> 1.52 +<body> 1.53 + 1.54 +EOF 1.55 +} 1.56 + 1.57 + 1.58 +function insertFooter() { 1.59 + echo <<EOF 1.60 + 1.61 +</body> 1.62 +</html> 1.63 +EOF 1.64 +} 1.65 + 1.66 + 1.67 +function log() { 1.68 + if [ $verbose ] ; then 1.69 + echo "$1"; 1.70 + fi 1.71 +} 1.72 + 1.73 + 1.74 +function checkConvert() { 1.75 + log "checking convert installation" 1.76 + (convert -version) 2> /dev/null > /dev/null 1.77 + if [ $? -ne 0 ] ; then 1.78 + echo "Error: Can not find 'convert' (package imagemagick)" 1.79 + echo "ABORT!" 1.80 + exit 2 1.81 + fi 1.82 + log "`convert -version`" 1.83 +} 1.84 + 1.85 + 1.86 +#### 1.87 + 1.88 + 1.89 + 1.90 +if [ $# -eq 0 ] ; then 1.91 + echo "usage: `basename $0` [OPTIONS] FILES" 1.92 + exit 0 1.93 +fi 1.94 + 1.95 + 1.96 +while [ "$#" -ge 1 -a "${1:0:1}" = '-' ] ; do 1.97 + case $1 in 1.98 + '--version') 1.99 + echo "genwebgallery version 0.3" 1.100 + exit 0 1.101 + ;; 1.102 + '--help') 1.103 + echo "`basename $0` 1.104 + 1.105 +generates a web gallery consisting of html pages 1.106 + 1.107 +usage: `basename $0` [OPTIONS] FILES 1.108 + 1.109 +options: 1.110 + --version: echo program version 1.111 + --help: display this output 1.112 + -v: be verbose 1.113 + -o DIR: all generated content is copied to this folder 1.114 + -i FILE: the name of the index file (index.htm) 1.115 + -t TITLE: title of the gallery 1.116 + -c COPYRIGHT: a copyright notice 1.117 + -ps PIXELS: size of the pics 1.118 + -ts PIXELS: size of the thumbnails 1.119 + 1.120 +author: meillo@marmaro.de 1.121 +homepage: http://prog.marmaro.de 1.122 +" 1.123 + exit 0 1.124 + ;; 1.125 + '-v' | '--verbose') 1.126 + verbose=1 1.127 + shift 1.128 + ;; 1.129 + '-o' | '--output') 1.130 + targetDir=$2 1.131 + shift 1.132 + shift 1.133 + ;; 1.134 + '-i' | '--index') 1.135 + index=$2 1.136 + shift 1.137 + shift 1.138 + ;; 1.139 + '-t' | '--title') 1.140 + galleryTitle=$2 1.141 + shift 1.142 + shift 1.143 + ;; 1.144 + '-c' | '--copyright') 1.145 + copyright=$2 1.146 + shift 1.147 + shift 1.148 + ;; 1.149 + '-ps' | '--pic-size') 1.150 + sizePic=$2 1.151 + shift 1.152 + shift 1.153 + ;; 1.154 + '-ts' | '--thumb-size') 1.155 + sizeThumb=$2 1.156 + shift 1.157 + shift 1.158 + ;; 1.159 + *) 1.160 + echo "invalid option: $1" 1.161 + echo "see: `basename $0` --help" 1.162 + exit 1 1.163 + esac 1.164 + 1.165 +done 1.166 + 1.167 +if [ $# -eq 0 ] ; then 1.168 + echo "usage: `basename $0` [OPTIONS] FILES" 1.169 + exit 0 1.170 +fi 1.171 + 1.172 + 1.173 +# verbose output 1.174 +log "verbose on" 1.175 +log "output dir is: $targetDir" 1.176 +log "index file is: $index" 1.177 +log "gallery title is: $galleryTitle" 1.178 +log "copyright notice is: $copyright" 1.179 +log "picture size is: $sizePic" 1.180 +log "thumbnail size is: $sizeThumb" 1.181 +checkConvert 1.182 +log "" 1.183 + 1.184 + 1.185 +checkCreateDir 1.186 + 1.187 +insertHeader > "$targetDir/$index" 1.188 +echo "<h1>$galleryTitle</h1>" >> "$targetDir/$index" 1.189 + 1.190 +for i in "$@" ; do 1.191 + file=`basename $i` 1.192 + targetFile="$targetDir/$file.htm" 1.193 + log "processing file: $file" 1.194 + 1.195 + # generate pic page 1.196 + insertHeader > "$targetFile" 1.197 + echo "<h1>$galleryTitle</h1>" \ 1.198 + "<p><a href=\"$index\"><img src=\"$file\" alt=\"$file\" /></a></p>" \ 1.199 + "<p>$copyright</p>" >> "$targetFile" 1.200 + insertFooter >> "$targetFile" 1.201 + 1.202 + # copy and resize pics 1.203 + convert "$i" -resize ${sizePic}x${sizePic} "$targetDir/$file" 1.204 + convert "$i" -resize ${sizeThumb}x${sizeThumb} "$targetDir/_$file" 1.205 + 1.206 + # generate content for index file 1.207 + echo " <a href=\"$file.htm\"><img src=\"_$file\" alt=\"$file\" /></a>" >> "$targetDir/$index" 1.208 +done 1.209 + 1.210 +echo "<p>$copyright</p>" >> "$targetDir/$index" 1.211 +insertFooter >> "$targetDir/$index"