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>
43 function bpgallery_default_tail() {
50 function bpgallery_default_stylesheet() {
55 font-family: sans-serif;
64 height: ${MAXHEIGHT}px;
77 if [[ -e /usr/local/etc/bpgallery/config ]] ; then
78 . /usr/local/etc/bpgallery/config
81 if [[ -e /etc/bpgallery/config ]] ; then
82 . /etc/bpgallery/config
85 if [[ -e $HOME/.bpgallery.rc ]]; then
89 if [[ -z ${BPGALLERY_THEME} ]]; then
90 BPGALLERY_THEME=default
93 if [[ -e $HOME/.bpgallery.themes/${BPGALLERY_THEME} ]]; then
94 . $HOME/.bpgallery.themes/${BPGALLERY_THEME}
95 elif [[ -e /usr/local/etc/bpgallery/themes/${BPGALLERY_THEME} ]]; then
96 . /usr/local/etc/bpgallery/themes/${BPGALLERY_THEME}
97 elif [[ -e /etc/bpgallery/themes/${BPGALLERY_THEME} ]]; then
98 . /etc/bpgallery/themes/${BPGALLERY_THEME}
101 if [[ -z $TITLE ]]; then
102 TITLE="Photo Gallery"
105 if [[ -z $CONVERTTOOL ]]; then
109 if [[ -z $FINDCOMMAND ]]; then
113 if [[ -z $XARGSCOMMAND ]]; then
117 if [[ -z $ECHOCOMMAND ]]; then
121 if [[ -z $SORTCOMMAND ]]; then
125 if [[ -z $IDENTIFYCOMMAND ]]; then
126 IDENTIFYCOMMAND=identify
129 if [[ -z $HEADCOMMAND ]]; then
133 if [[ -z $WIDTH ]]; then
137 if [[ -z $IMAGEEXTENSIONS ]]; then
138 IMAGEEXTENSIONS="jpeg jpg gif png";
141 if [[ -z $WCCOMMAND ]]; then
145 if declare -F "bpgallery_${BPGALLERY_THEME}_head" > /dev/null ; then
146 BPGALLERY_HEAD_FUNCTION="bpgallery_${BPGALLERY_THEME}_head"
148 BPGALLERY_HEAD_FUNCTION="bpgallery_default_head"
151 if declare -F "bpgallery_${BPGALLERY_THEME}_thumbsline" > /dev/null ; then
152 BPGALLERY_THUMBSLINE_FUNCTION="bpgallery_${BPGALLERY_THEME}_thumbsline"
154 BPGALLERY_THUMBSLINE_FUNCTION="bpgallery_default_thumbsline"
157 if declare -F "bpgallery_${BPGALLERY_THEME}_tail" > /dev/null ; then
158 BPGALLERY_TAIL_FUNCTION="bpgallery_${BPGALLERY_THEME}_tail"
160 BPGALLERY_TAIL_FUNCTION="bpgallery_default_tail"
163 if declare -F "bpgallery_${BPGALLERY_THEME}_stylesheet" > /dev/null ; then
164 BPGALLERY_STYLESHEET_FUNCTION="bpgallery_${BPGALLERY_THEME}_stylesheet"
166 BPGALLERY_STYLESHEET_FUNCTION="bpgallery_default_stylesheet"
171 for imageext in $IMAGEEXTENSIONS; do
172 FINDIMAGESOPTIONS=$FINDIMAGESOPTIONS' -o -type f -maxdepth 1 -iname '*.$imageext' -print0'
175 FINDIMAGESOPTIONS=${FINDIMAGESOPTIONS## -o }
180 $0 [--help|--version|<path to images>]
183 displays this help screen
185 displays the version and exits
202 if [[ "$1" == "--help" || "$1" == "-h" ]]; then
207 if [[ "$1" == "--version" || "$1" == "-v" ]]; then
212 if [[ ! -d $1 ]]; then
213 echo "$1 is not a directory"
220 if ( ! $FINDCOMMAND . $FINDIMAGESOPTIONS > /dev/null 2>/dev/null ); then
221 echo "$1 does not contain any images. Quitting."
225 if [ ! -d icons ]; then
228 echo "$1 already contains an icons folder, stopping"
232 totalimages=$($FINDCOMMAND . $FINDIMAGESOPTIONS | $XARGSCOMMAND -0 --replace echo {} | $WCCOMMAND);
235 $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
237 echo done: $totalimages/$totalimages images
239 $BPGALLERY_HEAD_FUNCTION > index.html
241 $FINDCOMMAND . $FINDIMAGESOPTIONS | $XARGSCOMMAND -0 --replace $ECHOCOMMAND {} |$SORTCOMMAND -g | while read filename; do filename=${filename#./}; $BPGALLERY_THUMBSLINE_FUNCTION; done >> index.html
243 $BPGALLERY_TAIL_FUNCTION >> index.html
247 for imageext in $IMAGEEXTENSIONS; do
248 if ( ls "*.$imageext" > /dev/null 2>/dev/null ); then
249 TEMPMAX=$($IDENTIFYCOMMAND *.$imageext | grep "Geometry:" | sed -r 's#^.*Geometry:.*?[0-9]+x([0-9]+)\+.*$#\1#' | $SORTCOMMAND -g -r | $HEADCOMMAND -n 1)
250 if [[ $TEMPMAX -gt $MAXHEIGHT ]]; then
259 $BPGALLERY_STYLESHEET_FUNCTION > style.css