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 declare -rf bpgallery_default_head
39 function bpgallery_default_description() {
46 declare -rf bpgallery_default_description
48 function bpgallery_default_thumbsline() {
50 <div class="thumbnail"><a href="$filename"><img src="icons/$filename" /></a><div class="caption">$caption</div></div>
54 declare -rf bpgallery_default_thumbsline
56 function bpgallery_default_tail() {
63 declare -rf bpgallery_default_tail
65 function bpgallery_default_stylesheet() {
70 font-family: sans-serif;
79 height: ${MAXHEIGHT}px;
98 declare -rf bpgallery_default_stylesheet
100 function bpgallery_escape_url() {
118 declare -rf bpgallery_escape_url
120 if [[ ! -z ${BPGALLERY_THEME} ]] ; then
121 declare -r BPGALLERY_THEME
124 if [[ ! -z ${TITLE} ]] ; then
128 if [[ -e /usr/local/etc/bpgallery/config ]] ; then
129 . /usr/local/etc/bpgallery/config 2>/dev/null
132 if [[ -e /etc/bpgallery/config ]] ; then
133 . /etc/bpgallery/config 2>/dev/null
136 if [[ -e $HOME/.bpgallery.rc ]]; then
137 . $HOME/.bpgallery.rc 2>/dev/null
140 if [[ -z ${BPGALLERY_THEME} ]]; then
141 BPGALLERY_THEME=default
144 if [[ -e $HOME/.bpgallery.themes/${BPGALLERY_THEME} ]]; then
145 . $HOME/.bpgallery.themes/${BPGALLERY_THEME} 2>/dev/null
146 elif [[ -e /usr/local/etc/bpgallery/themes/${BPGALLERY_THEME} ]]; then
147 . /usr/local/etc/bpgallery/themes/${BPGALLERY_THEME} 2>/dev/null
148 elif [[ -e /etc/bpgallery/themes/${BPGALLERY_THEME} ]]; then
149 . /etc/bpgallery/themes/${BPGALLERY_THEME} 2>/dev/null
152 if [[ -z $TITLE ]]; then
153 TITLE="Photo Gallery"
156 if [[ -z $CONVERTTOOL ]]; then
160 if [[ -z $FINDCOMMAND ]]; then
164 if [[ -z $XARGSCOMMAND ]]; then
168 if [[ -z $ECHOCOMMAND ]]; then
172 if [[ -z $SORTCOMMAND ]]; then
176 if [[ -z $IDENTIFYCOMMAND ]]; then
177 IDENTIFYCOMMAND=identify
180 if [[ -z $HEADCOMMAND ]]; then
184 if [[ -z $GREPCOMMAND ]]; then
188 if [[ -z $SEDCOMMAND ]]; then
192 if [[ -z $WIDTH ]]; then
196 if [[ -z $IMAGEEXTENSIONS ]]; then
197 IMAGEEXTENSIONS="jpeg jpg gif png";
200 if [[ -z $WCCOMMAND ]]; then
204 if [[ -z $CAPTIONHEIGHT ]]; then
208 if declare -F "bpgallery_${BPGALLERY_THEME}_head" > /dev/null ; then
209 BPGALLERY_HEAD_FUNCTION="bpgallery_${BPGALLERY_THEME}_head"
211 BPGALLERY_HEAD_FUNCTION="bpgallery_default_head"
214 if declare -F "bpgallery_${BPGALLERY_THEME}_description" > /dev/null ; then
215 BPGALLERY_DESCRIPTION_FUNCTION="bpgallery_${BPGALLERY_THEME}_description"
217 BPGALLERY_DESCRIPTION_FUNCTION="bpgallery_default_description"
220 if declare -F "bpgallery_${BPGALLERY_THEME}_thumbsline" > /dev/null ; then
221 BPGALLERY_THUMBSLINE_FUNCTION="bpgallery_${BPGALLERY_THEME}_thumbsline"
223 BPGALLERY_THUMBSLINE_FUNCTION="bpgallery_default_thumbsline"
226 if declare -F "bpgallery_${BPGALLERY_THEME}_tail" > /dev/null ; then
227 BPGALLERY_TAIL_FUNCTION="bpgallery_${BPGALLERY_THEME}_tail"
229 BPGALLERY_TAIL_FUNCTION="bpgallery_default_tail"
232 if declare -F "bpgallery_${BPGALLERY_THEME}_stylesheet" > /dev/null ; then
233 BPGALLERY_STYLESHEET_FUNCTION="bpgallery_${BPGALLERY_THEME}_stylesheet"
235 BPGALLERY_STYLESHEET_FUNCTION="bpgallery_default_stylesheet"
240 for imageext in $IMAGEEXTENSIONS; do
241 FINDIMAGESOPTIONS=$FINDIMAGESOPTIONS' -o -type f -iname '*.$imageext' -print0'
244 FINDIMAGESOPTIONS=${FINDIMAGESOPTIONS## -o }
245 FINDIMAGESOPTIONS='-maxdepth 1 '${FINDIMAGESOPTIONS}
250 $0 [--help|--version|<path to images>]
253 displays this help screen
255 displays the version and exits
272 if [[ "$1" == "--help" || "$1" == "-h" ]]; then
277 if [[ "$1" == "--version" || "$1" == "-v" ]]; then
282 if [[ ! -d $1 ]]; then
283 echo "$1 is not a directory"
290 if ( ! $FINDCOMMAND . $FINDIMAGESOPTIONS > /dev/null 2>/dev/null ); then
291 echo "$1 does not contain any images. Quitting."
295 if [ ! -d icons ]; then
298 totalimages=$($FINDCOMMAND . $FINDIMAGESOPTIONS | $XARGSCOMMAND -0 --replace echo {} | $WCCOMMAND);
301 $FINDCOMMAND . $FINDIMAGESOPTIONS | $XARGSCOMMAND -0 --verbose --max-procs=4 --replace $CONVERTTOOL -resize $WIDTH '{}' 'icons/{}' 2>&1 | while read throwout; do $ECHOCOMMAND done: $currentimage/$totalimages images; currentimage=$((currentimage+1)); done
303 echo done: $totalimages/$totalimages images
305 echo "$1 already contains an icons folder, updating."
307 imagestoupdate=$($FINDCOMMAND . $FINDIMAGESOPTIONS | $XARGSCOMMAND -0 --replace $ECHOCOMMAND {} | while read filename; do filename=${filename//\"/\\\"}; if [ ! -r "icons/$filename" ] || [ "$filename" -nt "icons/$filename" ]; then $ECHOCOMMAND $filename; fi; done | $WCCOMMAND)
309 echo "images to update: $imagestoupdate"
314 $FINDCOMMAND . $FINDIMAGESOPTIONS | $XARGSCOMMAND -0 --replace $ECHOCOMMAND {} | while read filename; do tempfilename=${filename//\"/\\\"/}; if [ ! -r "icons/$tempfilename" ] || [ "$tempfilename" -nt "icons/$tempfilename" ] ; then $ECHOCOMMAND -n $filename; $ECHOCOMMAND -n -e "\000"; fi; done | $XARGSCOMMAND -0 --verbose --max-procs=4 --replace $CONVERTTOOL -resize $WIDTH '{}' 'icons/{}' 2>&1 | while read throwout; do $ECHOCOMMAND done: $currentimage/$imagestoupdate images; echo $throwout; currentimage=$((currentimage+1)); done
315 echo done: $imagestoupdate/$imagestoupdate images
318 if [ -r description.txt ] ; then
319 DESCRIPTION=$($SEDCOMMAND -e '1 { s/^/<p>/; }; /^$/ { s,$,</p><p>,; }; $ { s,$,</p>, };' description.txt)
325 $BPGALLERY_HEAD_FUNCTION > index.html
326 $BPGALLERY_DESCRIPTION_FUNCTION >> index.html
328 $FINDCOMMAND . $FINDIMAGESOPTIONS | $XARGSCOMMAND -0 --replace $ECHOCOMMAND {} |$SORTCOMMAND -g | while read filename; do filename=${filename#./}; if [ -r captions.txt ]; then caption=$($GREPCOMMAND -E "^$filename " captions.txt); caption=${caption#* }; else caption=""; fi; filename=$(bpgallery_escape_url "$filename"); $BPGALLERY_THUMBSLINE_FUNCTION; done >> index.html
330 $BPGALLERY_TAIL_FUNCTION >> index.html
334 MAXHEIGHT=$($FINDCOMMAND . $FINDIMAGESOPTIONS | $XARGSCOMMAND -0 $IDENTIFYCOMMAND -format "%h\n" | $GREPCOMMAND -v "^$" | $SORTCOMMAND -g -r | $HEADCOMMAND -n 1)
335 MAXWIDTH=$($FINDCOMMAND . $FINDIMAGESOPTIONS | $XARGSCOMMAND -0 $IDENTIFYCOMMAND -format "%w\n" | $GREPCOMMAND -v "^$" | $SORTCOMMAND -g -r | $HEADCOMMAND -n 1)
339 # add a bit to the maxheight for the size of the caption
340 MAXHEIGHT=$((MAXHEIGHT+$CAPTIONHEIGHT))
342 $BPGALLERY_STYLESHEET_FUNCTION > style.css