3 # bpgallery.sh - builds a simple 'gallery' from a collection of images
4 # Copyright (C) 2004 Brett Parker <iDunno@sommitrealweird.co.uk>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 function bpgallery_default_head() {
27 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "xhtml11.dtd">
28 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
30 <title>${TITLE}</title>
31 <link rel="stylesheet" href="style.css" type="text/css" />
37 function bpgallery_default_thumbsline() {
39 <div class="thumbnail"><a href="$filename"><img src="icons/$filename" /></a><div class="caption">$caption</div></div>
43 function bpgallery_default_tail() {
50 function bpgallery_default_stylesheet() {
55 font-family: sans-serif;
64 height: ${MAXHEIGHT}px;
83 if [[ -e /usr/local/etc/bpgallery/config ]] ; then
84 . /usr/local/etc/bpgallery/config
87 if [[ -e /etc/bpgallery/config ]] ; then
88 . /etc/bpgallery/config
91 if [[ -e $HOME/.bpgallery.rc ]]; then
95 if [[ -z ${BPGALLERY_THEME} ]]; then
96 BPGALLERY_THEME=default
99 if [[ -e $HOME/.bpgallery.themes/${BPGALLERY_THEME} ]]; then
100 . $HOME/.bpgallery.themes/${BPGALLERY_THEME}
101 elif [[ -e /usr/local/etc/bpgallery/themes/${BPGALLERY_THEME} ]]; then
102 . /usr/local/etc/bpgallery/themes/${BPGALLERY_THEME}
103 elif [[ -e /etc/bpgallery/themes/${BPGALLERY_THEME} ]]; then
104 . /etc/bpgallery/themes/${BPGALLERY_THEME}
107 if [[ -z $TITLE ]]; then
108 TITLE="Photo Gallery"
111 if [[ -z $CONVERTTOOL ]]; then
115 if [[ -z $FINDCOMMAND ]]; then
119 if [[ -z $XARGSCOMMAND ]]; then
123 if [[ -z $ECHOCOMMAND ]]; then
127 if [[ -z $SORTCOMMAND ]]; then
131 if [[ -z $IDENTIFYCOMMAND ]]; then
132 IDENTIFYCOMMAND=identify
135 if [[ -z $HEADCOMMAND ]]; then
139 if [[ -z $GREPCOMMAND ]]; then
143 if [[ -z $WIDTH ]]; then
147 if [[ -z $IMAGEEXTENSIONS ]]; then
148 IMAGEEXTENSIONS="jpeg jpg gif png";
151 if [[ -z $WCCOMMAND ]]; then
155 if declare -F "bpgallery_${BPGALLERY_THEME}_head" > /dev/null ; then
156 BPGALLERY_HEAD_FUNCTION="bpgallery_${BPGALLERY_THEME}_head"
158 BPGALLERY_HEAD_FUNCTION="bpgallery_default_head"
161 if declare -F "bpgallery_${BPGALLERY_THEME}_thumbsline" > /dev/null ; then
162 BPGALLERY_THUMBSLINE_FUNCTION="bpgallery_${BPGALLERY_THEME}_thumbsline"
164 BPGALLERY_THUMBSLINE_FUNCTION="bpgallery_default_thumbsline"
167 if declare -F "bpgallery_${BPGALLERY_THEME}_tail" > /dev/null ; then
168 BPGALLERY_TAIL_FUNCTION="bpgallery_${BPGALLERY_THEME}_tail"
170 BPGALLERY_TAIL_FUNCTION="bpgallery_default_tail"
173 if declare -F "bpgallery_${BPGALLERY_THEME}_stylesheet" > /dev/null ; then
174 BPGALLERY_STYLESHEET_FUNCTION="bpgallery_${BPGALLERY_THEME}_stylesheet"
176 BPGALLERY_STYLESHEET_FUNCTION="bpgallery_default_stylesheet"
181 for imageext in $IMAGEEXTENSIONS; do
182 FINDIMAGESOPTIONS=$FINDIMAGESOPTIONS' -o -type f -maxdepth 1 -iname '*.$imageext' -print0'
185 FINDIMAGESOPTIONS=${FINDIMAGESOPTIONS## -o }
190 $0 [--help|--version|<path to images>]
193 displays this help screen
195 displays the version and exits
212 if [[ "$1" == "--help" || "$1" == "-h" ]]; then
217 if [[ "$1" == "--version" || "$1" == "-v" ]]; then
222 if [[ ! -d $1 ]]; then
223 echo "$1 is not a directory"
230 if ( ! $FINDCOMMAND . $FINDIMAGESOPTIONS > /dev/null 2>/dev/null ); then
231 echo "$1 does not contain any images. Quitting."
235 if [ ! -d icons ]; then
238 echo "$1 already contains an icons folder, stopping"
242 totalimages=$($FINDCOMMAND . $FINDIMAGESOPTIONS | $XARGSCOMMAND -0 --replace echo {} | $WCCOMMAND);
245 $FINDCOMMAND . $FINDIMAGESOPTIONS | $XARGSCOMMAND -0 --verbose --max-procs=4 --replace $CONVERTTOOL -resize $WIDTH '{}' 'icons/{}' 2>&1 | while read throwout; do echo done: $currentimage/$totalimages images; currentimage=$((currentimage+1)); done
247 echo done: $totalimages/$totalimages images
249 $BPGALLERY_HEAD_FUNCTION > index.html
251 $FINDCOMMAND . $FINDIMAGESOPTIONS | $XARGSCOMMAND -0 --replace $ECHOCOMMAND {} |$SORTCOMMAND -g | while read filename; do filename=${filename#./}; caption=$($GREPCOMMAND -E "^$filename " captions.txt); caption=${caption#* }; $BPGALLERY_THUMBSLINE_FUNCTION; done >> index.html
253 $BPGALLERY_TAIL_FUNCTION >> index.html
257 MAXHEIGHT=$($FINDCOMMAND . $FINDIMAGESOPTIONS | $XARGSCOMMAND -0 $IDENTIFYCOMMAND -format "%h\n" | $GREPCOMMAND -v "^$" | $SORTCOMMAND -g -r | $HEADCOMMAND -n 1)
261 # add a bit to the maxheight for the size of the caption
262 MAXHEIGHT=$((MAXHEIGHT+75))
264 $BPGALLERY_STYLESHEET_FUNCTION > style.css