you need the entire package to use the script,
version 0.03 and 0.04 are correct archive and works ( i tested em )
Btw, this is the script code
Code:
#! /bin/bash
# jGallery creates an html image gallery ready for uploading.
# Copyright (C) 2005 Josep Llodr� Grimalt
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# Contact: jlg.hrtc@gmail.com or http://herotyc.da.ru
#################################################
## USER VARIABLES ###############################
# dont change this unless you know what you're doing
WEBROOT_DIR=`pwd`'/web'
IMAGES_DIR='images'
THUMBS_DIR='thumbs'
INDEX_HTML_HEADER='index_header.template'
INDEX_HTML_FOOTER='index_footer.template'
CSS_FILE='gallery.css'
CSS_FILE_PHOTO='gallery_photo.css'
IMAGES_FIXED_WIDTH='800'
QUALITY='33' # jpeg quality (0..100) worst is 0
THUMBS_SIZE_H='240'
THUMBS_SIZE_V='184'
IMAGES_PER_PAGE=9
#################################################
## NON-USER VARIABLES ###########################
SCRIPTNAME="Html Image Gallery Script (jGallery)"
VERSION=0.04
COPYRIGHT="2005/06(c) Josep Llodr� (GNU GPL V.2)"
#################################################
## FUNCTIONS ####################################
# check_files
# - checks whether important files are present.
# 0 args
#
function check_files {
if [ ! -e "$INDEX_HTML_HEADER" -o \
! -e "$INDEX_HTML_FOOTER" -o \
! -e "$CSS_FILE" -o \
! -e "$CSS_FILE_PHOTO" ];
then
return 1
fi
which jhead &> /dev/null
if [ $? -ne 0 ]; then
return 2
fi
which convert &> /dev/null
if [ $? -ne 0 ]; then
return 3
fi
return 0
}
#################################################
# info
# - outputs some irrelevant info.
# 0 args
#
function info {
echo " "
echo "#################################################"
echo "$SCRIPTNAME "
echo "Ver. $VERSION"
echo "$COPYRIGHT"
echo "#################################################"
echo " "
return 0
}
#################################################
# check_dir
# - checks if an argument has been supplied and
# is a valid directory.
# 1 args
#
function check_dir {
case "$#" in
1) if [ -d "$1" ]; then
DIRECTORY="$1"
else
return 1
fi ;;
2) DIRECTORY="$1"
WEBROOT_DIR="$2"'/web' ;;
esac
return 0
}
#################################################
# check_images
# - checks for jpg and png images
# - counts images
# 0 args
#
function check_images {
ls "$DIRECTORY"/*.[Jj][Pp][Gg] "$DIRECTORY"/*.[Pp][Nn][Gg] 2>/dev/null
NUM_FILES=`ls "$DIRECTORY"/*.[Jj][Pp][Gg] "$DIRECTORY"/*.[Pp][Nn][Gg] 2>/dev/null | wc -l`
if [ "$NUM_FILES" -eq 0 ]; then
return 1
else
ls $DIRECTORY/*.[Jj][Pp][Gg] $DIRECTORY/*.[Pp][Nn][Gg] 2>/dev/null
echo "There are a total of $NUM_FILES images."
fi
return 0
}
#################################################
# prompt_user
# 0 args
#
function prompt_user {
read -p "Please give a name to the gallery: " GALLERY_NAME
if [ -z " $GALLERY_NAME " ]; then
$GALLERY_NAME = "My image Gallery!"
fi
echo "The gallery will be created in $WEBROOT_DIR directory"
read -p "Shall I create the gallery(and delete the previous one)? (Yy/Nn) " YesNo
case $YesNo in
N|n) return 1 ;;
*) echo "Building the gallery..."
echo "This process could take several minutes."
;;
esac
return 0
}
#################################################
# init
# - prepares everything:
# - deletes an older gallery
# - mkdirs, cp...
# 0 args
#
function init {
rm -Rf $WEBROOT_DIR
mkdir -p $WEBROOT_DIR/$IMAGES_DIR $WEBROOT_DIR/$THUMBS_DIR
cp $CSS_FILE $WEBROOT_DIR
cp $CSS_FILE_PHOTO $WEBROOT_DIR
}
#################################################
# page_count
# - counts how many pages are going to be needed
# 0 args
#
function page_count {
if [ `expr $NUM_FILES % $IMAGES_PER_PAGE` -eq 0 ];
then
NUM_PAGES=`expr $NUM_FILES / $IMAGES_PER_PAGE`
else
NUM_PAGES=`expr $NUM_FILES / $IMAGES_PER_PAGE + 1`
fi
return 0
}
#################################################
# create_headers
# - creates the html headers for all index files
# 0 args
#
function create_headers {
for num_index in `seq $NUM_PAGES`
do
if [ "$num_index" -eq 1 ];
then
filename="index.html"
else
filename="index$num_index.html"
fi
cat $INDEX_HTML_HEADER > $WEBROOT_DIR/$filename
echo "<title>Gallery : $GALLERY_NAME</title>" >> $WEBROOT_DIR/$filename
echo "<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"$CSS_FILE\">" >> $WEBROOT_DIR/$filename
echo "</head>" >> $WEBROOT_DIR/$filename
echo "<!-- header ends -->" >> $WEBROOT_DIR/$filename
echo "<!-- body begins -->" >> $WEBROOT_DIR/$filename
echo "<body>" >> $WEBROOT_DIR/$filename
echo "<h1>$GALLERY_NAME</h1>" >> $WEBROOT_DIR/$filename
echo '<div id="container">' >> $WEBROOT_DIR/$filename
echo ' <div id="image_list">' >> $WEBROOT_DIR/$filename
done
return 0
}
#################################################
# create_footers
# - creates the html footers for all index files
# 0 args
#
function create_footers {
for num_index in `seq $NUM_PAGES`
do
if [ "$num_index" -eq 1 ];
then
filename="index.html"
else
filename="index$num_index.html"
fi
cat >> $WEBROOT_DIR/$filename << EOF
</div>
<br class="clear" /> <!-- important! -->
</div>
<div id="pages">
<p>
EOF
case $num_index in
1) ;;
2) echo " <a href=\"index.html\">Prev</a>" >> $WEBROOT_DIR/$filename ;;
*) echo " <a href=\"index$(($num_index-1)).html\">Prev</a>" >> $WEBROOT_DIR/$filename ;;
esac
for num_page in `seq $NUM_PAGES`
do
if [ "$num_page" -ne "$num_index" ];
then
case $num_page in
1) echo " <a href=\"index.html\">$num_page</a>" >> $WEBROOT_DIR/$filename ;;
*) echo " <a href=\"index$num_page.html\">$num_page</a>" >> $WEBROOT_DIR/$filename;;
esac
else
echo "$num_page" >> $WEBROOT_DIR/$filename
fi
done
if [ "$num_index" -ne "$NUM_PAGES" ]; then
echo " <a href=\"index$(($num_index+1)).html\">Next</a>" >> $WEBROOT_DIR/$filename
fi
echo ' </p>' >> $WEBROOT_DIR/$filename
echo ' </div>' >> $WEBROOT_DIR/$filename
cat >> $WEBROOT_DIR/$filename << EOF
<div id="resum">
<!--<h3>Summary</h3>-->
<p>`date`</p>
<p>$NUM_FILES images.</p>
</div>
<!-- <div id="usuari">
<p>This script was executed by `whoami`, real name:
`grep ^\`whoami\` /etc/passwd | awk -F: '{print $5}' | \
awk -F, '{print $1}'`
</p>
</div> -->
EOF
cat $INDEX_HTML_FOOTER >> $WEBROOT_DIR/$filename
done
return 0
}
#################################################
## MAIN #########################################
#################################################
check_files
case "$?" in
1) echo "I cannot find the templates/css."; exit 1 ;;
2) echo "install jhead, please." ; exit 1 ;;
3) echo "install ImageMagick, please." ; exit 1 ;;
esac
info
if [ -z "$1" ]; then
echo "Usage: $0 directory_with_images [target_directory]"
exit 0
fi
check_dir "$@"
if [ " $? " -eq 1 ]; then
echo "$1 does not exist." 1>&2 ; exit 1
fi
check_images
if [ " $? " -eq 1 ]; then
echo "Sorry I could not find any image" 1>&2; exit 1
fi
prompt_user
if [ " $? " -eq 1 ]; then
exit 0
fi
init
page_count
create_headers
filename="index.html"; i=1; page=1
# for each image creates a thumbnail and a smaller image,
# html for the index and the entire image page.
ls "$DIRECTORY"/*.[Jj][Pp][Gg] "$DIRECTORY"/*.[Pp][Nn][Gg] 2>/dev/null | while read image
do
basename=`basename "$image" | awk '{ print substr($0,0,length($0)-4) }'`
extension=`basename "$image" | awk '{ print tolower(substr($0,length($0)-2,length($0))) }'`
length=$((`echo "$basename" | wc -c` - 1))
if [ "$length" -gt 25 ]; then
realname="${basename::25}..."
else
realname="$basename"
fi
thumb_time=`(time -p \
convert -size ${THUMBS_SIZE_H}x${THUMBS_SIZE_V} "$image" \
-resize ${THUMBS_SIZE_H}x${THUMBS_SIZE_V} -quality "$QUALITY" "$WEBROOT_DIR/$THUMBS_DIR/$basename.thumb.$extension" \
) 2>&1 | grep real | awk -F ' ' '{print $2}'`
image_time=`(time -p \
convert -size $IMAGES_FIXED_WIDTH "$image" \
-resize $IMAGES_FIXED_WIDTH -quality "$QUALITY" "$WEBROOT_DIR/$IMAGES_DIR/$basename.$extension" \
) 2>&1 | grep real | awk -F ' ' '{print $2}'`
#thumbs index
cat >> "$WEBROOT_DIR/$filename" << EOF
<dl>
<dt>
<a href="$i.html">
<img src="$THUMBS_DIR/$basename.thumb.$extension" width="$THUMBS_SIZE_H" height="$THUMBS_SIZE_V" alt="$basename"/>
</a>
</dt>
<dd>$realname</dd>
</dl>
EOF
#image index
image_footer=''
if [ -f "$DIRECTORY/$basename.txt" ]; then
image_footer=`cat "$DIRECTORY/$basename.txt"`
fi
image_size=`ls -lh "$WEBROOT_DIR/$IMAGES_DIR/$basename.$extension" \
| awk -F ' ' '{print $5}'`
if [ $extension = "jpg" ];
then
image_reso=`jhead "$WEBROOT_DIR/$IMAGES_DIR/$basename.$extension" \
| grep ^Resolution | awk -F: '{print $2}'`
else # png!
image_reso=`file -b "$WEBROOT_DIR/$IMAGES_DIR/$basename.$extension" \
| awk -F, '{print $2}'`
fi
# photopage header
cat $INDEX_HTML_HEADER > "$WEBROOT_DIR/$i.html"
echo "<title>Gallery : $GALLERY_NAME</title>" >> "$WEBROOT_DIR/$i.html"
echo "<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"$CSS_FILE_PHOTO\">" >> "$WEBROOT_DIR/$i.html"
echo "</head>" >> "$WEBROOT_DIR/$i.html"
echo "<!-- header ends -->" >> "$WEBROOT_DIR/$i.html"
echo "<!-- body begins -->" >> "$WEBROOT_DIR/$i.html"
echo "<body>" >> "$WEBROOT_DIR/$i.html"
#photopage body
cat >> "$WEBROOT_DIR/$i.html" << EOF
<div id="container">
<img src="$IMAGES_DIR/$basename.$extension" />
<p>$basename</p>
<p>$image_footer</p>
<p>$image_size $image_reso in ${image_time}s</p>
</div>
<div id="pages">
<p>
EOF
if [ $i -ne 1 ];
then
echo "<a href=\"$((i-1)).html\">«</a>" >> "$WEBROOT_DIR/$i.html"
fi
echo "<a href=\"$filename\">main</a>" >> "$WEBROOT_DIR/$i.html"
if [ $i -ne $NUM_FILES ];
then
echo "<a href=\"$((i+1)).html\">»</a>" >> "$WEBROOT_DIR/$i.html"
fi
cat >> "$WEBROOT_DIR/$i.html" << EOF
</p>
</div>
EOF
if [ $extension = "jpg" ]; #Exif headers
then
echo '<table id="exif">' >> "$WEBROOT_DIR/$i.html"
echo '<tr><td><h3> EXIF headers </h3></td></tr>' >> "$WEBROOT_DIR/$i.html"
jhead "$image" | awk -F: 'length($1) > 0 {print " <tr><th>",
$1, "</th><td>", $2, $3, $4, "</td></tr>"}' \
>> "$WEBROOT_DIR/$i.html"
echo "</table>" >> "$WEBROOT_DIR/$i.html"
fi
#photopage footer
cat $INDEX_HTML_FOOTER >> "$WEBROOT_DIR/$i.html"
#end check and debug output
echo "processing $image in page $page"
if [ `expr $i % $IMAGES_PER_PAGE` -eq 0 ];
then
((page++))
filename="index$page.html"
echo "switching page: $filename"
fi
((i++))
done
create_footers
exit 0
Let's wait for herotyc to relase the next version
byz