+ $ECHOCOMMAND "Completed generating $2 for $totalimages images"
+}
+
+function generate_thumbs() {
+ if [ ! -d icons ]; then
+ mkdir icons
+ fi
+
+ if [ ! -w icons ]; then
+ $ECHOCOMMAND "Can't write to icons directory, exiting"
+ exit 16
+ fi
+
+ generate_resized_images $WIDTH icons
+}
+
+function generate_medium() {
+ if [ ! -d medium ]; then
+ mkdir medium
+ fi
+
+ if [ ! -w medium ]; then
+ $ECHOCOMMAND "Can't write to medium directory, exiting"
+ exit 32
+ fi
+
+ generate_resized_images $MEDIUMWIDTH medium
+}
+
+function generate_pages() {
+ $ECHOCOMMAND "Generating Pages"
+ previouspage=""
+ currentpage=""
+ nextpage=""
+ previousimage=""
+ currentimage=""
+ nextimage=""
+ extra=""
+ extradir=""
+ addlinks=0
+
+ if [ ! -z $1 ]; then
+ extra=$1
+ fi
+
+ if [ ! -z $2 ]; then
+ extradir=$2/
+ addlinks=1
+ fi
+
+ if [ -z $1 ] && [ -z $2 ] && [[ $GENERATEPAGESFORMEDIUMSIZE != 0 ]]; then
+ addlinks=2
+ fi
+
+ $FINDCOMMAND . $FINDIMAGESOPTIONS | \
+ $XARGSCOMMAND -0 -I {} $ECHOCOMMAND {} | \
+ $SORTCOMMAND -g | \
+ while read imagefilename; do
+ previousimage=$currentimage
+ currentimage=$nextimage
+ nextimage=${imagefilename#./}
+ addlink=""
+
+ if [[ $addlinks == 1 ]]; then
+ if [[ $GENERATEPAGESFORFULLSIZE != 0 ]]; then
+ addlink=${currentimage}.html
+ else
+ addlink=${currentimage}
+ fi
+ fi
+
+ if [[ $addlinks == 2 ]]; then
+ addlink=${currentimage}__medium.html
+ fi
+
+ previouspage=$currentpage
+ currentpage=$nextpage
+ nextpage=${imagefilename}${extra}.html
+ filename=${extradir}${currentimage}
+ generate_general_page "$previouspage" "$currentpage" "$nextpage" $addlink
+ echo $nextimage
+ done | tail -n 2 | (
+ read previouspage
+ read currentpage
+ addlink=""
+
+ if [[ $addlinks == 1 ]]; then
+ if [[ $GENERATEPAGESFORFULLSIZE ]]; then
+ addlink=${currentpage}.html
+ else
+ addlink=${currentpage}
+ fi
+ fi
+
+ if [[ $addlinks == 2 ]]; then
+ addlink=${nextimage}__medium.html
+ fi
+
+ filename=${extradir}${currentpage}
+ currentpage=${currentpage}${extra}.html
+ previouspage=${previouspage}${extra}.html
+ nextpage=""
+ generate_general_page "$previouspage" "$currentpage" "" $addlink
+ )
+}
+
+function generate_medium_pages() {
+ generate_pages __medium medium
+}
+
+function generate_general_page() {
+
+ if [[ -z $1 ]]; then
+ previouspage=""
+ fi
+
+ if [[ -z $2 ]]; then
+ currentpage=""
+ return
+ fi
+
+ if [[ -z $3 ]]; then
+ nextpage=""
+ fi
+
+ if [[ ! -z $4 ]]; then
+ linklocation=$4
+ fi
+
+ if [ -r captions.txt ]; then
+ caption=$($GREPCOMMAND -E "^${filename} " captions.txt); caption=${caption#* }
+ else
+ caption=""
+ fi
+
+ $BPGALLERY_PAGE_FUNCTION > "$currentpage"