#!/bin/bash ########################################################################## # # Description : Convert a Gthumb catalog to Original web-gallery # Author : Pierre Gaigé (pgaige at free.fr) # Date : 2006/01/29 # Licence : GPL V2 ########################################################################## # # ------------------------------------------------------------------------ # Change the following line to fit your needs GALLERY_DIR="/data/WEB" # CATALOG_DIR=$(echo -e ~/.gnome2/gthumb/collections) # ------------------------------------------------------------------------ # Catalog to convert if [ -z "$(ls $CATALOG_DIR/*.gqv 2>/dev/null)" ] then zenity --error --title "Error !" --text "No Gthumb catalog found ! Please, create one." exit 1 else catalog=$(ls $CATALOG_DIR/*.gqv | awk -F'/' '{print $NF}' | sed 's/.gqv//' | \ zenity --list --width 300 --height 400 --title "gallery" --text "Choose Gthumb catalog to convert" --column "Catalog") [ -z "$catalog" ] && exit 1 fi # ------------------------------------------------------------------------ # Scaler program GdkPixbufConvert="gdk-pixbuf-convert" Convert="convert" scaler=$(which $GdkPixbufConvert 2>/dev/null) if [ -z "$scaler" ] then scaler=$(which $Convert 2>/dev/null) if [ -z "$scaler" ] then zenity --error --title "Error !" --text "No scaling program found. You need to have $GdkPixbufConvert or $Convert available." exit 1 fi fi # ------------------------------------------------------------------------ # Scan Catalog for files filelist=$(cat "$CATALOG_DIR/$catalog.gqv") [ -z "$filelist" ] && zenity --error --title "Error !" --text "Catalog does not contain any photo" && exit 1 filelist=$(echo "$filelist" | sort) # ------------------------------------------------------------------------ # Create directory structure [ -d "$GALLERY_DIR" ] && dir="$GALLERY_DIR/$catalog" || dir="/tmp/$catalog" make_dir () { [ ! -d "$1" ] && mkdir -p "$1" 2>/dev/null [ $? -ne 0 ] && zenity --error --title "Error !" --text "Fatal error : Cannot create $1" && exit 1 } [ -e "$dir" ] && zenity --error --title "Error !" --text \ "$(echo -e "Gallery \"$catalog\" already exist...\nPlease, remove it first !\n\nDirectory is \"$dir\"")" && exit 1 make_dir "$dir" make_dir "$dir/thumbs" make_dir "$dir/lq" make_dir "$dir/mq" make_dir "$dir/hq" make_dir "$dir/comments" make_dir "$dir/zip" # ------------------------------------------------------------------------ # Web elements choice choice=$(zenity --list --checklist --height 250 --title "Web elements" --text="Choose web elements to generate" \ --column="Generate" --column="Web element" TRUE mq FALSE hq TRUE comment FALSE zip) # ------------------------------------------------------------------------ # Initialize counters num_of_args=$(echo "$filelist" | wc -w) # Nb of increments per file : thumbs, lq, mq, hq, comment (2 mini + nb of choice) let NumOfIncrements="$(echo $choice | sed -e 's/|zip//' -e 's/|/ /g' | wc -w) + 2" let increment="100 / ($num_of_args * $NumOfIncrements)" progress=0 i=1 SetDirDate=0 # ------------------------------------------------------------------------ # Now process ( for file in $filelist do file=$(echo "$file" | sed 's/^\"//' | sed 's/\"$//') echo "$file" if [ -d "$file" ] # argument is a directory, skip it then let "$progress += ($increment * $NumOfIncrements)" echo "$progress" continue fi FileType=$(\file "$file") if [ -z "$(echo $FileType | egrep 'image data')" ] # check for valid file type # Bug .xcf return image data then let "progress += ($increment * $NumOfIncrements)" echo "$progress" continue fi # Set the date of the gallery if [ "$SetDirDate" -eq 0 ] # we are looking at the first image then SetDirDate=$(stat -c %Z "$file") # get mtime if [ "$SetDirDate" -ge 0 ] # set mtime of gallery directory to the one of the first image one then touch -r "$file" "$dir" echo "Setting mtime of $dir to $SetDirDate" else SetDirDate=0 fi fi # Create thumbnails $scaler -geometry 120x120 -quality 60 "$file" "$dir/thumbs/img-$i.jpg" 2>&1 let "progress += $increment" echo "$progress" # LQ size $scaler -geometry 640x480 -quality 75 "$file" "$dir/lq/img-$i.jpg" 2>&1 let "progress += $increment" echo "$progress" # MQ size [ -n "$(echo $choice | grep 'mq')" ] && $scaler -geometry 800x600 -quality 75 "$file" "$dir/mq/img-$i.jpg" 2>&1 let "progress += $increment" echo "$progress" # HQ size (just copy the original) [ -n "$(echo $choice | grep 'hq')" ] && cp "$file" "$dir/hq/img-$i.jpg" 2>&1 let "progress += $increment" echo "$progress" # comment if [ -n "$(echo $choice | grep 'comment')" ] then echo "image $i" > "$dir/comments/$i.txt" xmlfile=$(dirname "$file")/.comments/$(basename "$file").xml if [ -e "$xmlfile" ] # image has a comment then # decode comment place=$(zcat "$xmlfile" | sed -e '//!d' -e 's/^.*//' -e 's/<\/Place>.*$//') note=$(zcat "$xmlfile" | sed -e '//!d' -e 's/^.*//' -e 's/<\/Note>.*$//') [ -n "$place" ] && echo "
Lieu : $place" >> "$dir/comments/$i.txt" [ -n "$note" ] && echo "
Note : $note" >> "$dir/comments/$i.txt" fi fi let "progress += $increment" echo "$progress" let "i += 1" done ) | zenity --progress --auto-close --title="cat2gal" --text="Scaling images, please wait" # ------------------------------------------------------------------------ # Zip files if [ -n "$(echo $choice | grep 'zip')" ] then ( [ -n "$(echo $choice | grep 'mq')" ] && zip "$dir"/zip/mq.zip "$dir"/mq/*.jpg [ -n "$(echo $choice | grep 'hq')" ] && zip "$dir"/zip/hq.zip "$dir"/hq/*.jpg ) | zenity --progress --pulsate --auto-close --title " " --text "Zipping images" fi # ------------------------------------------------------------------------ # Put info file - Standard info.txt file must be present # - adapt editor to your preferences if zenity --question --title="Gallery info" --text "Do you want to put an info.txt file" then if [ -f "$GALLERY_DIR/info.txt" ] then cp "$GALLERY_DIR/info.txt" "$dir" [ "$(which gedit)" ] && gedit --encoding=UTF-8 "$dir/info.txt" || zenity --info --text "Please edit \"info.txt\" file" else zenity --warning --text "No standard \"info.txt\" file found ! Please create one" fi fi # ------------------------------------------------------------------------ # Continue with FTP ?!