]> git.sommitrealweird.co.uk Git - bpgallery.git/blob - bpgallery.sh
Make icons and medium image directories non-hardcoded
[bpgallery.git] / bpgallery.sh
1 #!/usr/bin/env bash
2
3 # bpgallery.sh - builds a simple 'gallery' from a collection of images
4 # Copyright (C) 2004 Brett Parker <iDunno@sommitrealweird.co.uk>
5 #
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.
10
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.
15
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
19
20 set -f
21
22 VERSION="1.1.1+arch"
23
24 function bpgallery_default_head() {
25 cat <<END
26 <?xml version="1.0"?>
27 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "xhtml11.dtd">
28 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
29 <head>
30         <title>${TITLE}</title>
31         <link rel="stylesheet" href="${BASEURL}style.css" type="text/css" />
32 </head>
33 <body>
34 END
35 }
36
37 declare -rf bpgallery_default_head
38
39 function bpgallery_default_description() {
40 cat <<END
41         <h1>${TITLE}</h1>
42         ${DESCRIPTION}
43 END
44 }
45
46 declare -rf bpgallery_default_description
47
48 function bpgallery_default_thumbsline() {
49 if [[ -z $caption ]]; then
50         caption_alt=Unknown
51 else
52         caption_alt=$caption
53 fi
54 cat << END
55 <div class="thumbnail"><a href="$link"><img src="${ICONSDIRECTORY}/$filename" alt="$caption_alt" /></a><div class="caption">$caption</div></div>
56 END
57 }
58
59 declare -rf bpgallery_default_thumbsline
60
61 function bpgallery_default_tail() {
62 cat << END
63 </body>
64 </html>
65 END
66 }
67
68 declare -rf bpgallery_default_tail
69
70 function bpgallery_default_stylesheet() {
71 cat <<END
72 body {
73         background: white;
74         color: black;
75         font-family: sans-serif;
76         font-size: 10pt;
77 }
78
79 div.thumbnail {
80         float: left;
81         padding: 20px;
82         border: 0px;
83         width: ${WIDTH}px;
84         height: ${MAXHEIGHT}px;
85 }
86
87 div.caption {
88         width: 100%;
89         text-align: center;
90         font-weight: bold;
91 }
92
93 div.navigation {
94         margin: 0;
95 }
96
97 div.navigation ul {
98         display: inline;
99         margin: 0;
100         padding: 0;
101         text-align: center;
102 }
103
104 div.navigation ul li {
105         display: inline;
106         margin: 2em;
107 }
108
109 a {
110         border: 0px;
111 }
112
113 img {
114         border: 0px;
115 }
116 END
117 }
118
119 declare -rf bpgallery_default_stylesheet
120
121 function bpgallery_default_page() {
122         $BPGALLERY_HEAD_FUNCTION
123
124         linkstart=""
125         linkend=""
126
127         if [[ ! -z $linklocation ]]; then
128                 linkstart="<a href='$linklocation'>"
129                 linkend="</a>"
130         fi
131         
132         cat <<END
133 <h1>${caption}</h1>
134 <div class="navigation">
135         <ul>
136                 <li><a href='${BASEURL}${INDEXDOCUMENT}'>Thumbnails</a></li>
137 END
138         if [[ ! -z $previouspage ]]; then
139                 $ECHOCOMMAND "<li><a href='${previouspage}'>Previous</a></li>"
140         else
141                 $ECHOCOMMAND "<li>Previous</li>"
142         fi
143
144         if [[ ! -z $nextpage ]]; then
145                 $ECHOCOMMAND "<li><a href='${nextpage}'>Next</a></li>"
146         else
147                 $ECHOCOMMAND "<li>Next</li>"
148         fi
149 cat <<END
150         </ul>
151 </div>
152 <div class="mainimage">
153         ${linkstart}<img src="${filename}" alt="${caption}" />${linkend}
154 </div>
155 END
156         $BPGALLERY_TAIL_FUNCTION
157 }
158
159 declare -rf bpgallery_default_page
160
161 function bpgallery_escape_url() {
162         temp=$1
163         temp=${temp//\%/%25}
164         temp=${temp//:/%3A}
165         temp=${temp//;/%3B}
166         temp=${temp// /%20}
167         temp=${temp//$/%24}
168         temp=${temp//&/%26}
169         temp=${temp//+/%2B}
170         temp=${temp//,/%2C}
171         temp=${temp//\//%2F}
172         temp=${temp//=/%3D}
173         temp=${temp//\?/%3F}
174         temp=${temp//@/%40}
175         temp=${temp//\"/%22}
176         $ECHOCOMMAND $temp
177 }
178
179 function bpgallery_cleanup_directory_name() {
180         temp=$1
181         temp=${temp//\%/_}
182         temp=${temp//:/_}
183         temp=${temp//;/_}
184         temp=${temp// /_}
185         temp=${temp//$/_}
186         temp=${temp//&/_}
187         temp=${temp//+/_}
188         temp=${temp//,/_}
189         temp=${temp//\//_}
190         temp=${temp//=/_}
191         temp=${temp//\?/_}
192         temp=${temp//@/_}
193         temp=${temp//\"/_}
194         $ECHOCOMMAND $temp
195 }
196
197 declare -rf bpgallery_escape_url
198
199 if [[ ! -z ${BPGALLERY_THEME} ]] ; then
200         declare -r BPGALLERY_THEME
201 fi
202
203 if [[ ! -z ${TITLE} ]] ; then
204         declare -r TITLE
205 fi
206
207 if [[ -e /usr/local/etc/bpgallery/config ]] ; then
208         . /usr/local/etc/bpgallery/config 2>/dev/null
209 fi
210
211 if [[ -e /etc/bpgallery/config ]] ; then
212         . /etc/bpgallery/config 2>/dev/null
213 fi
214
215 if [[ -e $HOME/.bpgallery.rc ]]; then
216         . $HOME/.bpgallery.rc 2>/dev/null
217 fi
218
219 if [[ -e $1 && -d $1 && -e $1/.bpgallery.rc ]]; then
220         . $1/.bpgallery.rc 2>/dev/null
221 fi
222
223 if [[ -z ${BPGALLERY_THEME} ]]; then
224         BPGALLERY_THEME=default
225 fi
226
227 if [[ ! -z ${BPGALLERY_THEME_DIR} ]] && \
228         [[ -e ${BPGALLERY_THEME_DIR}/${BPGALLERY_THEME} ]]; then
229         . ${BPGALLERY_THEME_DIR}/${BPGALLERY_THEME} 2>/dev/null
230 elif [[ -e $HOME/.bpgallery.themes/${BPGALLERY_THEME} ]]; then
231         . $HOME/.bpgallery.themes/${BPGALLERY_THEME} 2>/dev/null
232 elif [[ -e /usr/local/etc/bpgallery/themes/${BPGALLERY_THEME} ]]; then
233         . /usr/local/etc/bpgallery/themes/${BPGALLERY_THEME} 2>/dev/null
234 elif [[ -e /etc/bpgallery/themes/${BPGALLERY_THEME} ]]; then
235         . /etc/bpgallery/themes/${BPGALLERY_THEME} 2>/dev/null
236 fi
237
238 if [[ -z $TITLE ]]; then 
239         TITLE="Photo Gallery"
240 fi
241
242 if [[ -z $CONVERTTOOL ]]; then
243         CONVERTTOOL=convert
244 fi
245
246 if [[ -z $FINDCOMMAND ]]; then
247         FINDCOMMAND=find
248 fi
249
250 if [[ -z $XARGSCOMMAND ]]; then
251         XARGSCOMMAND=xargs
252 fi
253
254 if [[ -z $ECHOCOMMAND ]]; then
255         ECHOCOMMAND=echo
256 fi
257
258 if [[ -z $SORTCOMMAND ]]; then
259         SORTCOMMAND=sort
260 fi
261
262 if [[ -z $IDENTIFYCOMMAND ]]; then
263         IDENTIFYCOMMAND=identify
264 fi
265
266 if [[ -z $HEADCOMMAND ]]; then
267         HEADCOMMAND=head
268 fi
269
270 if [[ -z $GREPCOMMAND ]]; then
271         GREPCOMMAND=grep
272 fi
273
274 if [[ -z $SEDCOMMAND ]]; then
275         SEDCOMMAND=sed
276 fi
277
278 if [[ -z $WIDTH ]]; then
279         WIDTH=100
280 fi
281
282 if [[ -z $IMAGEEXTENSIONS ]]; then
283         IMAGEEXTENSIONS="jpeg jpg gif png";
284 fi
285
286 if [[ -z $WCCOMMAND ]]; then
287         WCCOMMAND="wc -l"
288 fi
289
290 if [[ -z $CAPTIONHEIGHT ]]; then
291         CAPTIONHEIGHT=75
292 fi
293
294 if [[ -z $OUTPUTHTML ]]; then
295         OUTPUTHTML=0
296 fi
297
298 if [[ -z $GENERATEPAGESFORFULLSIZE ]]; then
299         GENERATEPAGESFORFULLSIZE=0
300 fi
301
302 if [[ -z $GENERATEPAGESFORMEDIUMSIZE ]]; then
303         GENERATEPAGESFORMEDIUMSIZE=1
304 fi
305
306 if [[ -z $PAGESDIRECTORY ]]; then
307         PAGESDIRECTORY=""
308 else
309         removetrailingslashes=${PAGESDIRECTORY%/}
310         temp=$removetrailingslashes
311         while [[ $removetrailingslashes != $temp ]]; do
312                 temp=$removetrailingslashes
313                 removetrailingslashes=${temp%/}
314         done
315         PAGESDIRECTORY=$(bpgallery_escape_url "${PAGESDIRECTORY}")
316 fi
317
318 if [[ -z $MEDIUMWIDTH ]]; then
319         MEDIUMWIDTH=400
320 fi
321
322 if [[ -z $INDEXDOCUMENT ]]; then
323         INDEXDOCUMENT=index.html
324 fi
325
326 if [[ -z $MEDIUMDIRECTORY ]]; then
327         MEDIUMDIRECTORY=medium
328 else
329         # Strip out anything that might be broken
330         MEDIUMDIRECTORY=$(bpgallery_cleanup_directory_name "$MEDIUMDIRECTORY")
331 fi
332
333 if [[ -z $ICONSDIRECTORY ]]; then
334         ICONSDIRECTORY=icons
335 else
336         # Strip out anything that might be broken
337         ICONSDIRECTORY=$(bpgallery_cleanup_directory_name "$ICONSDIRECTORY")
338 fi
339
340 if declare -F "bpgallery_${BPGALLERY_THEME}_page" > /dev/null ; then
341         BPGALLERY_PAGE_FUNCTION="bpgallery_${BPGALLERY_THEME}_page"
342 else
343         BPGALLERY_PAGE_FUNCTION="bpgallery_default_page"
344 fi
345
346 if declare -F "bpgallery_${BPGALLERY_THEME}_head" > /dev/null ; then
347         BPGALLERY_HEAD_FUNCTION="bpgallery_${BPGALLERY_THEME}_head"
348 else
349         BPGALLERY_HEAD_FUNCTION="bpgallery_default_head"
350 fi
351
352 if declare -F "bpgallery_${BPGALLERY_THEME}_description" > /dev/null ; then
353         BPGALLERY_DESCRIPTION_FUNCTION="bpgallery_${BPGALLERY_THEME}_description"
354 else
355         BPGALLERY_DESCRIPTION_FUNCTION="bpgallery_default_description"
356 fi
357
358 if declare -F "bpgallery_${BPGALLERY_THEME}_thumbsline" > /dev/null ; then
359         BPGALLERY_THUMBSLINE_FUNCTION="bpgallery_${BPGALLERY_THEME}_thumbsline"
360 else
361         BPGALLERY_THUMBSLINE_FUNCTION="bpgallery_default_thumbsline"
362 fi
363
364 if declare -F "bpgallery_${BPGALLERY_THEME}_tail" > /dev/null ; then
365         BPGALLERY_TAIL_FUNCTION="bpgallery_${BPGALLERY_THEME}_tail"
366 else
367         BPGALLERY_TAIL_FUNCTION="bpgallery_default_tail"
368 fi
369
370 if declare -F "bpgallery_${BPGALLERY_THEME}_stylesheet" > /dev/null ; then
371         BPGALLERY_STYLESHEET_FUNCTION="bpgallery_${BPGALLERY_THEME}_stylesheet"
372 else
373         BPGALLERY_STYLESHEET_FUNCTION="bpgallery_default_stylesheet"
374 fi
375
376 FINDIMAGESOPTIONS=""
377
378 for imageext in $IMAGEEXTENSIONS; do
379         FINDIMAGESOPTIONS=$FINDIMAGESOPTIONS' -o -type f -iname '*.$imageext' -print0'
380 done
381
382 FINDIMAGESOPTIONS=${FINDIMAGESOPTIONS## -o }
383 FINDIMAGESOPTIONS='-maxdepth 1 '${FINDIMAGESOPTIONS}
384
385 function usage() {
386 cat <<END
387 Usage:
388   $0 [--help|--version|<path to images>]
389
390     --help
391         displays this help screen
392     --version
393         displays the version and exits
394
395 This can also takes some environment variables, these will use defaults if not
396 set.
397
398         TITLE
399             the title of the gallery
400
401         WIDTH
402             the width to make the icons
403
404         MEDIUMWIDTH
405             set the width of images in the medium size pages
406
407         BPGALLERY_THEME
408             set the theme to use (described below)
409
410         BPGALLERY_THEME_DIR
411             set an extra location to look for themes
412
413         OUTPUTHTML
414             sets the script output to be wrapped in a <pre> block
415
416         GENERATEPAGESFORMEDIUMSIZE
417             generate medium sized images and pages
418
419         GENERATEPAGESFORFULLSIZE
420             decide wether to generate pages for the full size images or not
421
422         INDEXDOCUMENT
423             name of the index page (e.g. index.html)
424
425 Example:
426         TITLE="My Funky Gallery" WIDTH=200 INDEXDOCUMENT="welcome.html" GENERATEPAGESFORFULLSIZE=1 GENERATEPAGESFORMEDIUMSIZE=1 MEDIUMWIDTH=400 $0 /path/to/image/folder
427 END
428 }
429
430 function version() {
431 cat <<END
432 Version: $VERSION
433 END
434 }
435
436 function generate_resized_images() {
437         $ECHOCOMMAND "Generating $2"
438         currentimage=0
439         totalimages=$($FINDCOMMAND . $FINDIMAGESOPTIONS | $XARGSCOMMAND -0 -I {} $ECHOCOMMAND {} | $WCCOMMAND);
440         imagestoupdate=$($FINDCOMMAND . $FINDIMAGESOPTIONS | $XARGSCOMMAND -0 -I {} $ECHOCOMMAND {} | while read filename; do filename=${filename//\"/\\\"}; if [ ! -r "$2/$filename" ] || [ "$filename" -nt "$2/$filename" ] || [ $($IDENTIFYCOMMAND -format "%w" "$2/$filename") -ne $1 ]; then $ECHOCOMMAND $filename; fi; done | $WCCOMMAND)
441         
442         if [ $totalimages -eq 0 ]; then
443                 # might as well exit at this point - there are no pictures
444                 $ECHOCOMMAND "No images for the gallery - exiting."
445                 exit 64
446         else
447                 # check if the directory exists and create it other wise
448                 if [ ! -d $2 ]; then
449                         mkdir $2
450                 fi
451
452                 if [ ! -w $2 ]; then
453                         $ECHOCOMMAND "Can't write to $2 directory, exiting"
454                         exit 16
455                 fi
456         fi
457
458         if [ $totalimages -eq $imagestoupdate ]; then
459                 $ECHOCOMMAND "Regenerating all $2"
460         elif [ $imagestoupdate -eq 0 ]; then
461                 $ECHOCOMMAND "No Updated $2, not regenerating"
462                 return
463         else
464                 $ECHOCOMMAND "Generating $imagestoupdate of $totalimages $2"
465         fi
466         
467         $FINDCOMMAND . $FINDIMAGESOPTIONS | $XARGSCOMMAND -0 -I {} $ECHOCOMMAND {} | while read filename; do tempfilename=${filename//\"/\\\"/}; if [ ! -r "$2/$tempfilename" ] || [ "$tempfilename" -nt "$2/$tempfilename" ] || [ $($IDENTIFYCOMMAND -format "%w" "$2/$filename") -ne $1 ]; then $ECHOCOMMAND -n $filename; $ECHOCOMMAND -n -e "\000"; fi; done | $XARGSCOMMAND -0 --verbose --max-procs=4 -I {} $CONVERTTOOL -resize $1 '{}' $2/'{}' 2>&1 | while read throwout; do $ECHOCOMMAND done: $currentimage/$imagestoupdate images; currentimage=$((currentimage+1)); done
468         $ECHOCOMMAND done: $imagestoupdate/$imagestoupdate images
469         $ECHOCOMMAND "Completed generating $2 for $totalimages images"
470 }
471
472 function generate_thumbs() {
473         generate_resized_images $WIDTH $ICONSDIRECTORY
474 }
475
476 function generate_medium() {
477         generate_resized_images $MEDIUMWIDTH $MEDIUMDIRECTORY
478 }
479
480 function generate_pages() {
481         $ECHOCOMMAND "Generating Pages"
482         previouspage=""
483         currentpage=""
484         nextpage=""
485         previousimage=""
486         currentimage=""
487         nextimage=""
488         extra=""
489         extradir=""
490         addlinks=0
491         
492         if [ ! -z $1 ]; then
493                 extra=$1
494         fi
495
496         if [ ! -z $2 ]; then
497                 extradir=$2/
498                 addlinks=1
499         fi
500
501         if [ -z $2 ] && [[ $GENERATEPAGESFORMEDIUMSIZE != 0 ]]; then
502                 addlinks=2
503         fi
504         
505         $FINDCOMMAND . $FINDIMAGESOPTIONS | \
506         $XARGSCOMMAND -0 -I {} $ECHOCOMMAND {} | \
507         $SORTCOMMAND -g | \
508         while read imagefilename; do
509                 previousimage=$currentimage
510                 currentimage=$nextimage
511                 nextimage=${imagefilename#./}
512                 addlink=""
513                 
514                 if [[ $GENERATEPAGESFORFULLSIZE != 0 ]]; then
515                         if [[ $addlinks == 1 ]]; then
516                                 addlink=${currentimage}.html
517                         else
518                                 addlink=${currentimage}${extra}.html
519                         fi
520                 else
521                         addlink=${currentimage}
522                 fi
523
524                 previouspage=$currentpage
525                 currentpage=$nextpage
526                 if [[ $addlinks == 1 ]]; then
527                         nextpage=${nextimage}${extra}.html
528                 else
529                         nextpage=${nextimage}.html
530                 fi
531
532                 if [[ "x$PAGESDIRECTORY" != "x" ]]; then
533                         filename=../${extradir}${currentimage}
534                 else
535                         filename=${extradir}${currentimage}
536                 fi
537                 if [ "x$currentpage" != "x" ]; then
538                         generate_general_page "$previouspage" "$currentpage" "$nextpage" $addlink
539                 fi
540                 $ECHOCOMMAND $nextimage
541         done | tail -n 2 | (
542                 read previouspage
543                 read currentpage
544                 addlink=""
545
546                 if [[ $GENERATEPAGESFORFULLSIZE != 0 ]]; then
547                         if [[ $addlinks == 1 ]]; then
548                                 addlink=${currentpage}.html
549                         else
550                                 addlink=${currentpage}${extra}.html
551                         fi
552                 else
553                         addlink=${currentpage}
554                 fi
555                 
556                 if [[ "x$PAGESDIRECTORY" != "x" ]]; then
557                         filename=../${extradir}${currentpage}
558                 else
559                         filename=${extradir}${currentpage}
560                 fi
561                 if [[ $addlinks == 1 ]]; then
562                         currentpage=${currentpage}${extra}.html
563                         previouspage=${previouspage}${extra}.html
564                 else
565                         currentpage=${currentpage}.html
566                         previouspage=${previouspage}.html
567                 fi
568                 nextpage=""
569                 generate_general_page "$previouspage" "$currentpage" "" $addlink
570         )
571 }
572
573 function generate_medium_pages() {
574         generate_pages __${MEDIUMDIRECTORY} ${MEDIUMDIRECTORY}
575 }
576
577 function generate_general_page() {
578
579         if [[ -z $1 ]]; then
580                 previouspage=""
581         fi
582
583         if [[ -z $2 ]]; then
584                 currentpage=""
585                 return
586         fi
587
588         if [[ -z $3 ]]; then
589                 nextpage=""
590         fi
591
592         if [[ ! -z $4 ]]; then
593                 linklocation=$4
594         fi
595
596         if [ -r captions.txt ]; then
597                 imagefilename=${filename##*/}
598                 caption=$($GREPCOMMAND -E "^${imagefilename}    " captions.txt); caption=${caption#*    }
599         else
600                 caption=""
601         fi
602         
603         $BPGALLERY_PAGE_FUNCTION > "${UNIXPAGESDIRECTORY}$currentpage"
604 }
605
606 if [[ $OUTPUTHTML != 0 ]]; then
607         $ECHOCOMMAND "<pre>"
608 fi
609
610 if [[ -z $1 ]]; then
611         $ECHOCOMMAND "No path given"
612         usage
613         exit 1
614 fi
615
616 if [[ "$1" == "--help" || "$1" == "-h" ]]; then
617         usage
618         exit 0
619 fi
620
621 if [[ "$1" == "--version" || "$1" == "-v" ]]; then
622         version
623         exit 0
624 fi
625
626 if [[ ! -d $1 ]]; then
627         $ECHOCOMMAND "$1 is not a directory"
628         usage
629         exit 2
630 fi
631
632 cd "$1"
633
634 if ( ! $FINDCOMMAND . $FINDIMAGESOPTIONS > /dev/null 2>/dev/null ); then
635         $ECHOCOMMAND "$1 does not contain any images. Quitting."
636         exit 4
637 fi
638
639 if [ ! -w . ]; then
640         $ECHOCOMMAND "Can't write to images directory, exiting"
641         exit 8
642 fi
643
644 if [ -e ${INDEXDOCUMENT} ] && [ ! -w ${INDEXDOCUMENT} ]; then
645         $ECHOCOMMAND "Can't write ${INDEXDOCUMENT}, exiting"
646         exit 8
647 fi
648
649 if [ -e style.css ] && [ ! -w style.css ]; then
650         $ECHOCOMMAND "Can't write style.css, exiting"
651         exit 8
652 fi
653
654 generate_thumbs
655
656 if [[ "x$PAGESDIRECTORY" != "x" ]]; then
657         if [ ! -d $PAGESDIRECTORY ]; then
658                 mkdir -p $PAGESDIRECTORY
659         fi
660
661         if [ ! -w $PAGESDIRECTORY ]; then
662                 $ECHOCOMMAND "Can't write to $PAGESDIRECTORY directory, exiting"
663                 exit 16
664         fi
665         UNIXPAGESDIRECTORY=$PAGESDIRECTORY/     
666         PAGESDIRECTORY=$(bpgallery_escape_url $PAGESDIRECTORY)/
667
668         BASEURL="../"
669 else
670         BASEURL=""
671         UNIXPAGESDIRECTORY=""
672 fi
673
674 if [ $GENERATEPAGESFORMEDIUMSIZE != 0 ]; then
675         generate_medium
676         generate_medium_pages
677 fi
678
679 if [ $GENERATEPAGESFORFULLSIZE != 0 ]; then
680         if [ $GENERATEPAGESFORMEDIUMSIZE != 0 ]; then
681                 generate_pages __${MEDIUMDIRECTORY}
682         else
683                 generate_pages
684         fi
685 fi
686
687 if [ -r description.txt ] ; then
688         DESCRIPTION=$($SEDCOMMAND -e '1 { s/^/<p>/; }; /^$/ { s,$,</p><p>,; }; $ { s,$,</p>, };' description.txt)
689 else
690         DESCRIPTION=""
691 fi
692
693 BASEURL=""
694
695 $ECHOCOMMAND "Starting to generate page"
696
697 $BPGALLERY_HEAD_FUNCTION > ${INDEXDOCUMENT}
698 $BPGALLERY_DESCRIPTION_FUNCTION >> ${INDEXDOCUMENT}
699
700 $ECHOCOMMAND "Adding Captions"
701
702 extra=""
703 if [ $GENERATEPAGESFORMEDIUMSIZE != 0 ]; then
704         extra=__${MEDIUMDIRECTORY}
705 fi
706
707 $FINDCOMMAND . $FINDIMAGESOPTIONS | $XARGSCOMMAND -0 -I {} $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; if [ $GENERATEPAGESFORMEDIUMSIZE != 0 ]; then link=${PAGESDIRECTORY}$(bpgallery_escape_url "${filename}${extra}.html"); elif [ $GENERATEPAGESFORFULLSIZE != 0 ]; then link=${PAGESDIRECTORY}$(bpgallery_escape_url "${filename}.html"); else link=$(bpgallery_escape_url "$filename"); fi; filename=$(bpgallery_escape_url "$filename"); $BPGALLERY_THUMBSLINE_FUNCTION; done >> ${INDEXDOCUMENT}
708
709 $BPGALLERY_TAIL_FUNCTION >> ${INDEXDOCUMENT}
710
711 $ECHOCOMMAND "Finished generating the page"
712 $ECHOCOMMAND "Generating stylesheet"
713 cd $ICONSDIRECTORY
714
715 MAXHEIGHT=$($FINDCOMMAND . $FINDIMAGESOPTIONS | $XARGSCOMMAND -0 $IDENTIFYCOMMAND -format "%h\n" | $GREPCOMMAND -v "^$" | $SORTCOMMAND -g -r | $HEADCOMMAND -n 1)
716 MAXWIDTH=$($FINDCOMMAND . $FINDIMAGESOPTIONS | $XARGSCOMMAND -0 $IDENTIFYCOMMAND -format "%w\n" | $GREPCOMMAND -v "^$" | $SORTCOMMAND -g -r | $HEADCOMMAND -n 1)
717
718 cd ..
719
720 # add a bit to the maxheight for the size of the caption
721 MAXHEIGHT=$((MAXHEIGHT+$CAPTIONHEIGHT))
722
723 $BPGALLERY_STYLESHEET_FUNCTION > style.css
724
725 $ECHOCOMMAND "All done"
726
727 if [[ $OUTPUTHTML != 0 ]]; then
728         $ECHOCOMMAND "</pre>"
729 fi