Register
It is currently Mon Jul 28, 2014 6:20 am

jGallery0.03


All times are UTC - 6 hours


Post new topic Reply to topic  [ 15 posts ] 
Author Message
 PostPosted: Fri Oct 06, 2006 10:40 am   

Joined: Fri Oct 06, 2006 10:34 am
Posts: 7
This bash script let's you create an html image gallery ready for upload to your webserver.

Download link.

An example gallery.

More info.

Please tell me if you improve it.


Top
 Profile WWW  
 PostPosted: Fri Oct 06, 2006 10:58 am   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 662
Location: Des Moines, Iowa
Just had a quick look at the example gallery... i'll look more later ...... looks nice :)


Top
 Profile WWW  
 PostPosted: Fri Oct 06, 2006 11:24 am   

Joined: Mon Sep 18, 2006 1:16 pm
Posts: 27
looks nice! i might have to use this script to help me organise my image collection (over 100 images!)

one suggestion, IF it's possible, maybe add the ability to convert pics names that have spaces to maybe underscores during copy (i assume images are copied, havent had a chance to use the script yet)?

this way its even easier to use.


Top
 Profile  
 PostPosted: Fri Oct 06, 2006 1:35 pm   

Joined: Fri Oct 06, 2006 10:34 am
Posts: 7
Ok, first of all thanks for all your comments :)

katasuka wrote:
one suggestion, IF it's possible, maybe add the ability to convert pics names that have spaces to maybe underscores during copy (i assume images are copied, havent had a chance to use the script yet)?


Yes... I know this "spacing" issue, I'll try to do a fix/workaround as soon as possible.
Btw, the images are scaled for a fixed width of 800 pixels, in order to save space... I could make the size customizable for the next version(and do some html/css code cleanup too).


Top
 Profile WWW  
 PostPosted: Fri Oct 06, 2006 3:12 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 662
Location: Des Moines, Iowa
I have a gallery function in my bbips scripts...... but had never implemented the multiple pages thing...... looking at the way you did this. May integrate something similar into my bbips programs.


Top
 Profile WWW  
 PostPosted: Sat Oct 07, 2006 12:04 pm   

Joined: Fri Oct 06, 2006 10:34 am
Posts: 7
Spacing issue fixed.


Top
 Profile WWW  
 PostPosted: Thu Oct 26, 2006 3:37 pm   

Joined: Fri Oct 06, 2006 10:34 am
Posts: 7
New version out with minor but important changes... Basically I added a _jpeg compression_ variable to make galleries smaller, and also a README file which surely will be useful.

jGallery0.04

More things to come.


Top
 Profile WWW  
 PostPosted: Tue Jun 12, 2007 9:17 am   
User avatar

Joined: Tue Jun 12, 2007 9:12 am
Posts: 3
just tried, really cool.
if i can suggest something..
you should insert a prompt to choose background color or title font and size and so on ( well, css details )
They're few details, but i think they're not too difficult to write down, and it will make your script more professional.

Anyway, good work.


Top
 Profile WWW  
 PostPosted: Tue Jun 12, 2007 9:51 am   

Joined: Fri Oct 06, 2006 10:34 am
Posts: 7
n0on3 wrote:
you should insert a prompt to choose background color or title font and size and so on ( well, css details )

I had this thing in mind. My intention was to make it more beautiful and more customizable. I still have to think about this but I want to make a modular css system(several css files, and use combinations of them), and also add more user variables. It would be also nice to include some other javascript effects. A pity I dont have the time to do so right now.

Anyway, thanks for your comment


Top
 Profile WWW  
 PostPosted: Wed Jun 13, 2007 10:22 am   

Joined: Wed May 30, 2007 9:22 pm
Posts: 39
Location: California
i keep getting errors when I try to unpack the archive...any way someone can post the raw code in this thread? I would love to try this script out!

DeX


Top
 Profile  
 PostPosted: Wed Jun 13, 2007 11:38 am   
User avatar

Joined: Tue Jun 12, 2007 9:12 am
Posts: 3
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\">&laquo;</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\">&raquo;</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


Top
 Profile WWW  
 PostPosted: Wed Jun 13, 2007 1:04 pm   

Joined: Wed May 30, 2007 9:22 pm
Posts: 39
Location: California
thanks! I finally got the archive to unzip correctly...not sure what was going on with it...i dig this script! I hope you don't mind me making changes to the .css files for background color and such.


Top
 Profile  
 PostPosted: Tue Jun 26, 2007 7:45 pm   

Joined: Fri Oct 06, 2006 10:34 am
Posts: 7
DeX wrote:
I hope you don't mind me making changes to the .css files for background color and such.

Cool!

Would you mind sending me all the changes you made? I'd include them in the package and credit you

Oh! Forgot to say there is a new version: jGallery0.05


Top
 Profile WWW  
 PostPosted: Tue Jul 24, 2007 2:10 pm   

Joined: Wed May 30, 2007 9:22 pm
Posts: 39
Location: California
Hey herotyc,

I was wondering if you have considered doing this project in Python or another language and building a front end for it? If you are interested, I would be willing to help you out with it. I am going to try and get a python script going that does exactly what your bash script does for a start.

DeX


Top
 Profile  
 PostPosted: Wed Jul 25, 2007 8:55 am   

Joined: Fri Oct 06, 2006 10:34 am
Posts: 7
To be honest I don't have the time to do so. This bash script is more than enough for me now.

Anyway, if you are willing to do a gallery generator with Python, you can start looking at this one in Ruby: http://www.soledadpenades.com/2007/06/2 ... d-builder/

It's not as complex as jGallery but can be a good starting point for you.


Top
 Profile WWW  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP