[juneau-lug] Re: Resizing jpegs

  • From: Jamie <jamie@xxxxxxxxxxxxxxxxx>
  • To: juneau-lug@xxxxxxxxxxxxx
  • Date: Tue, 10 Aug 2004 11:57:05 -0800

Here is a script that I've been using (I didn't write it).  Its a bit 
buggy but it does alot.  It builds web page(s) of thumbnails linked to 
your (resized) images.  It uses  ImageMagick's "convert" program for the 
resizing / image manipulation.  As a back burner project, I'd like to 
clean up the bugs and write a UI for it.

See http://shawley.myip.org/projects/photogen.php

#!/bin/bash
# Thanks to Matt Hansen for finding that stupid quote I missed.
# Thanks to Gontran for his tip about the undefined var error.
# Thanks to ASM on irc.linux.com for some other good tips
curdir=`pwd`/
clear
echo "============================================"
echo "========   Welcome to PHOTO-GEN    ========="
echo "============================================"
echo "= This script will create a photo album    ="
echo "= From a directory jpgs or gifs.           ="
echo "============================================"
echo "=                                          ="
echo "= Created by Jeremy Shawley                ="
echo "= For more information, please visit:      ="
echo "= http://shawley.myip.org                  ="
echo "= or email me:                             ="
echo "= jshawley@xxxxxxxxxxxxxxxx                ="
echo "=                                          ="
echo "============================================"
echo ""
echo "============================================"
echo "= Lets get started.                        ="
echo "= Press Enter to Continue, or ctl-c to quit="
echo "============================================"
echo ""

read GETSTARTED
# set XWIN so bash doesn't bitch
XWIN="N"
# set CAPT so bash will quit bitching
CAPT="n"
CAPTBACK="n"
RESIZE="n"
RESIZEH="800"
RESIZEV="600"
PGVERSION=1.9b
HEADER="----------------------------------- PhotoGen $PGVERSION"

#
# Get Directory Path
#
clear

echo "$HEADER"
echo ""
echo "=========================================="
echo "What is the full path to the directory"
echo "of your pictures you would like to use?"
echo "=========================================="
echo ""
echo "[ $curdir ]"
echo ""
echo "Press Enter for Default"
echo "------------------------------------------"
read DIRPATH

if [ "$DIRPATH" = "" ]
    then
    DIRPATH=$curdir
fi

clear
echo "$HEADER"
echo ""
echo "=========================================="
echo "Is this path correct"
echo "($DIRPATH)?"
echo "(y or n)"
echo "=========================================="
read YESORNO

if [ $YESORNO = "y" ] || [ $YESORNO = "Y" ]
    then
    if [ ! -d $DIRPATH ]
        then
        echo "Sorry, directory does not exist - Exiting"
        echo "Please run photogen again with the correct path"
        echo ""
        exit 0
    fi
     echo ""
    echo "============================================"
    echo "Creating thumbnails from this path:"
    echo "$DIRPATH"
    echo "============================================"
    echo ""

#
# change to current path
#

cd $DIRPATH

else
    exit
fi

# file count for images
FLCOUNT="$(ls *.[jJgG][pPiI][gGfF] | wc -w)"

# Set log file
LOGFILE=$DIRPATH/photogen.log
if [ -e $LOGFILE ]
    then
    echo "READING LOG FILE"
    . $LOGFILE
fi

#New log file
LOGFILE=$DIRPATH/photogen.log.tmp
cat /dev/null > $LOGFILE
   
clear

#
# Archive Original Images
#
echo "$HEADER"
echo ""
echo "=========================================="
echo "Would you like to archive your original"
echo "Images? (y or n)"
echo "(Default is no)"
echo "=========================================="
read BACKUP

if [ $BACKUP = "y" ] || [ $BACKUP = "Y" ]
then
    if [ ! -d $DIRPATH/archive ]
                then
               mkdir $DIRPATH/archive
               echo "============================================"
            echo "Created Directory archive to store originals"
            echo "============================================"
    fi
   
    cp -u *.[jJgG][pPiI][gGfF] $DIRPATH/archive
   
               echo "============================================"
            echo "Original Images Archived to: "
        echo "$DIRPATH/archive/"
            echo "============================================"
        echo ""
        echo "Press Enter to Continue"
        echo ""
        read JUNK
fi

#
# Set firstpage name
#

PAGENAME=index.html

FIRSTPAGENAME=$PAGENAME


#
# Give Gallery a name
#

clear
echo "$HEADER"
echo ""
echo "============================================"
echo "Please give your gallery a name:"
if [ "$PGGALNAME" != "" ]
    then
    echo "Default is $PGGALNAME"
    echo "Press Enter for Default"
fi
echo "============================================"
read GALNAME
if [ "$GALNAME" = "" ]
    then
    GALNAME=$PGGALNAME
fi
echo "PGGALNAME=\"$GALNAME\"" >> $LOGFILE

clear
#
# Get caption stuff
#

echo "$HEADER"
echo ""

    if [ -e $DIRPATH/captions.txt ]
    then
    echo "============================================"
    echo "I see that you have already run PhotoGen"
    echo "and have saved captions for your images"
    echo "If you have not added or removed any"
    echo "images from the current directory, you can"
    echo "have PhotoGen put the captions back on your"
    echo "images for you. "
    echo "would you like to do this? (y or n)"
    echo "============================================"
    read CAPTBACK

    echo "PGCAPTBACK=$CAPTBACK" >> $LOGFILE

        if [ $CAPTBACK = "y" ] || [ $CAPTBACK = "Y" ]
        then
        CAPT = "n"
        else
        echo "============================================"
        echo "Moving old captions file to"
        echo "$DIRPATH/captions.old"
        echo "============================================"
        mv $DIRPATH/captions.txt $DIRPATH/captions.old
        fi
    fi

if [ $CAPTBACK = "" ] || [ $CAPTBACK = "n" ] || [ $CAPTBACK = "N" ]
    then
    echo "============================================"
    echo "Would you like to put captions on your images?"
    echo "(y or n)"
    echo "============================================"
    read CAPT

    echo "PGCAPT=$CAPT" >> $LOGFILE

    echo ""

    if [ $CAPT = "y" ] || [ $CAPT = "Y" ]
    then
    echo "============================================"
    echo "Are you using Xwindows?"
    echo "(y or n)"
    echo "============================================"
    read XWIN
   
    echo "PGXWIN=$XWIN" >> $LOGFILE
    echo ""
    fi
fi

clear

#
# Get size of lowres
#

echo "$HEADER"
echo ""
echo "============================================"
echo "What size of thumbnails would you like?"
echo "============================================"
echo ""

if [ -d $DIRPATH/lowres ]
        then
    echo "=============== WARNING ====================="
    echo "I see that you already have a lowres"
    echo "directory, If you are changing lowres size"
    echo "you should remove the files in the lowres"
    echo "directory. Would you like me to do that"
    echo "for you? (y or n)"
    echo "============================================="
    read REMOVE
   
    echo "PGREMOVE=$REMOVE" >> $LOGFILE

    if [ $REMOVE = "y" ] || [ $REMOVE = "Y" ]
            then
        rm -r $DIRPATH/lowres
        echo ""
    echo "============================================="
    echo "Please choose thumbnail size "
    echo "============================================="
   
    else   
    echo "============================================="
    echo "Please choose thumbnail size - This will only"
    echo "effect any new images you have added to the"
    echo "current working directory"
    echo "============================================="
    fi   
fi
    if [ "$PGIMAGESIZE" != "" ]
    then
    echo "Your previous choice was $PGIMAGESIZE"
    echo ""
    fi
echo "1. 100 x 100 - Small"
echo "2. 150 x 150 - Medium - Best Choice"
echo "3. 200 x 200 - Large"
echo "============================================"
read IMAGESIZE

echo "PGIMAGESIZE=$IMAGESIZE" >> $LOGFILE
echo ""
if [ $IMAGESIZE = "1" ]
    then
    IMAGESIZE="100x100"
    COUNT="5"
elif [ $IMAGESIZE = "2" ]
    then
    IMAGESIZE="150x150"
    COUNT="4"
elif [ $IMAGESIZE = "3" ]
    then
    IMAGESIZE="200x200"
    COUNT="3"
else
    echo "Sorry, Invalid choice, exiting"
        exit
fi

if [ $COUNT -eq 5 ]
        then
        PPDEF=20
elif [ $COUNT -eq 4 ]
        then
        PPDEF=12
elif [ $COUNT -eq 3 ]
        then
        PPDEF=9
fi

clear
echo "$HEADER"
echo ""
#
#How many pictures per page
#
echo "============================================"
echo "How many thumbnails would you like per page?"
echo "($PPDEF is default.)"
echo "You have chosen an image size of $IMAGESIZE "
echo "This means the html table is $COUNT images wide"
echo "Be sure the number of images on the page"
echo "is divisible by that number"
echo "Press enter for default"
echo "============================================"
read PERPAGE


if [ "$PERPAGE" = "" ]
        then
        PERPAGE=$PPDEF
fi

echo "PGPERPAGE=$PERPAGE" >> $LOGFILE

echo ""
FLCOUNT=$(expr $FLCOUNT + 0)
echo "INFO -------------------------------"
echo "You have a total of $FLCOUNT images"
echo "$PERPAGE images per page and a total"

TLPAGES=$(expr $FLCOUNT / $PERPAGE)

REMANDER=$(($PERPAGE * $TLPAGES))
if [ $REMANDER -ne $FLCOUNT ]
    then
    TLPAGES=$(( $TLPAGES + 1))
fi   
echo "of $TLPAGES pages"
echo "-----------------------------------"
echo ""
echo "Press enter to continue"
read GETSTARTED


#
# Choose lowresing large images also
#
clear
echo "$HEADER"
echo ""
echo "==============================================="
echo "Would you like to change your "
echo "High res pictures to 72 dpi also?"
echo "(Most scanners do 150 by default, however,"
echo "the web prefers 72 dpi for images."
echo "Also, images are much faster to load at 72 dpi"
echo "(y or n)"
echo "================================================"
read HIRES

echo "PGHIRES=$HIRES" >> $LOGFILE

clear

#
# Resize originals to 640 x 480
#

echo "$HEADER"
echo ""
echo "============================================"
echo "Would you like to resize your original"
echo "Images?"
echo "(You will want to do this if you find your"
echo "images are larger than a typical computer"
echo "screen, I found this to be true with"
echo "pictures from my digital camera.)"
echo "(y or n)"
echo "============================================"
read RESIZE

        if [ $RESIZE = "y" ] || [ $RESIZE = "Y" ]
    then
        echo "============================================"
        echo "Please choose size you would like to use"
        echo "============================================"
        echo "1. 640 x 480 (small)"
        echo "2. 800 x 600 (medium)"
        echo "3. 1024 x 768 (large)"
        echo "============================================"
        echo ""
        read RESIZE
   
        if [ $RESIZE = "1" ]
            then
            RESIZEH="640"
            RESIZEV="480"
        elif [ $RESIZE = "2" ]
            then
                        RESIZEH="800"
                        RESIZEV="600"
        elif [ $RESIZE = "3" ]
            then
                        RESIZEH="1024"
                        RESIZEV="768"
        else
            echo "Sorry, Invalid choice, exiting"
            exit
        fi
        RESIZE="y"
    fi

clear
#
# ask how they would like the pictures sorted
#

echo "$HEADER"
echo ""
echo "============================================"
echo "How would you like the pictures sorted?"
echo "============================================"
echo " 1. Alphabetically"
echo " 2. Numerically"
read SORT

echo "PGSORT=$SORT" >>$LOGFILE

if [ $SORT = "1" ]
    then
     SORT="$(ls *.[jJgG][pPiI][gGfF])"   
elif  [ $SORT = "2" ]
    then
    SORT="$(ls *.[jJgG][pPiI][gGfF]|sort -n)"
else
    echo "Sorry, Invalid choice, exiting"
    exit
fi

clear
#
# Make Thumbnails
#

echo "$HEADER"
echo ""
echo "Creating Thumbnails"

if [ ! -d $DIRPATH/lowres ]
    then
    mkdir $DIRPATH/lowres
    echo "============================================"
    echo "Created Directory lowres to store thumbnails"
    echo "============================================"
fi

if [ ! -e $DIRPATH/$PAGENAME ]
    then
    touch $DIRPATH/$PAGENAME
else
    echo "==============================================="
    echo "WARNING: $PAGENAME is there, removing old file"
    echo "==============================================="
    rm $DIRPATH/$PAGENAME
    touch $DIRPATH/$PAGENAME
    echo ""
fi

echo "==============================================="
echo "Building New $PAGENAME template"
echo "==============================================="
echo ""

clear

#
# Choose background Color
#
echo "$HEADER"
echo ""
echo "==============================================="
echo "What color would you like the background?"
echo "For examples of theses colors, please open"
echo "then bgcolors.html that came with photogen,"
echo "or go to http://shawley.myip.org/colors.html";
echo "==============================================="
echo "1. Steel Grey <default> 7. Dim Gray"
echo "2. Alice Blue           8. Rosy Brown"
echo "3. Antique White        9. Teal"
echo "4. Beige               10. Tan"
echo "5. Dark Sea Green      11. Steel Blue"
echo "6. Midnight Blue       12. Indian Red"
echo ""
echo "Please choose 1 - 12"
read BGCOLOR

echo "PGBGCOLOR=$BGCOLOR" >> $LOGFILE

if [ $BGCOLOR = "1" ]
    then
    BGCOLOR=#778899
elif [ $BGCOLOR = "2" ]
    then
    BGCOLOR=#F0F8FF
elif [ $BGCOLOR = "3" ]
        then
        BGCOLOR=#FAEBD7
elif [ $BGCOLOR = "4" ]
        then
        BGCOLOR=#F5F5DC
elif [ $BGCOLOR = "5" ]
        then
        BGCOLOR=#8FBC8F
elif [ $BGCOLOR = "6" ]
        then
        BGCOLOR=#191970
elif [ $BGCOLOR = "7" ]
        then
        BGCOLOR=#696969
elif [ $BGCOLOR = "8" ]
        then
        BGCOLOR=#BC8F8F
elif [ $BGCOLOR = "9" ]
        then
        BGCOLOR=#008080
elif [ $BGCOLOR = "10" ]
        then
        BGCOLOR=#D2B48C
elif [ $BGCOLOR = "11" ]
        then
        BGCOLOR=#4682B4
elif [ $BGCOLOR = "12" ]
        then
        BGCOLOR=#CD5C5C
else
        BGCOLOR=#778899
fi

clear
#
# Home URL
#
echo "$HEADER"
echo ""
echo "==============================================="
echo "Would you like to link (URL) back to your"
echo "main home page?"
echo "(y or  n)"
echo "==============================================="
echo ""
read URL
    if [ $URL = "y" ] || [ $URL = "Y" ]
    then
        echo ""
        echo "==============================================="
        echo "Please enter your home page address (URL)"
        if [ "$PGURL" != "" ]
        then
        echo "Default: $PGURL"
        fi
        echo "==============================================="
        read URLHOME
        if [ "$URLHOME" = "" ]
        then
        URLHOME=$PGURL
        fi

    echo "PGURL=\"$URLHOME\"" >> $LOGFILE
    fi
   

clear

#
# Making $PAGENAME template
#

echo "<HTML><HEAD>" >> $DIRPATH/$PAGENAME
echo "<TITLE> $GALNAME </TITLE>" >> $DIRPATH/$PAGENAME
echo "<SCRIPT TYPE=\"text/javascript\">" >> $DIRPATH/$PAGENAME
echo "<!-- " >> $DIRPATH/$PAGENAME
echo "function popup(mylink, windowname)" >> $DIRPATH/$PAGENAME
echo "{" >> $DIRPATH/$PAGENAME
echo "if (! window.focus)return true;" >> $DIRPATH/$PAGENAME
echo "var href;" >> $DIRPATH/$PAGENAME
echo "if (typeof(mylink) == 'string') " >> $DIRPATH/$PAGENAME
echo "   href=mylink;" >> $DIRPATH/$PAGENAME
echo "else " >> $DIRPATH/$PAGENAME
echo "   href=mylink.href;" >> $DIRPATH/$PAGENAME
echo "window.open(href, windowname, 
'width=$RESIZEH,height=$RESIZEV,scrollbars=yes');" >> $DIRPATH/$PAGENAME
echo "return false;" >> $DIRPATH/$PAGENAME
echo "}" >> $DIRPATH/$PAGENAME
echo "//--> " >> $DIRPATH/$PAGENAME
echo "</SCRIPT>" >> $DIRPATH/$PAGENAME
echo "</HEAD><BODY bgcolor=$BGCOLOR>" >> $DIRPATH/$PAGENAME
echo "<center><H1> $GALNAME</H1></center>" >> $DIRPATH/$PAGENAME

if [ $URL = "y" ] || [ $URL = "Y" ]
    then
    echo "<center><font size=5><a href=$URLHOME >HOME</a> </center>" >> 
$DIRPATH/$PAGENAME
fi

if [ $TLPAGES -gt 1 ]
then
echo "<center><font size =5>PAGE: " >> $DIRPATH/$PAGENAME
x=1
until [ "$x" -gt $TLPAGES ]
    do
    if [ $x -eq 1 ]
    then
        echo "<a href=index.html>$x </a>" >> $DIRPATH/$PAGENAME
        x=$(expr $x + 1)
    else
    echo "<a href=page$x.html>$x </a>" >> $DIRPATH/$PAGENAME
        x=$(expr $x + 1)
    fi
    if [ $x -lt $TLPAGES ] || [ $x -eq $TLPAGES ]
    then
    echo " - " >>$DIRPATH/$PAGENAME
    fi
done
echo "</font></center>" >>$DIRPATH/$PAGENAME

fi


echo "<p><center><table bgcolor=#CCCCC border=2 cellpadding=20 
cellspacing=2><tr>" >> $DIRPATH/$PAGENAME


clear
#
# Echo back about creating thumbnails
#

echo ""
echo "==============================================="
echo "Now Generating Thumb Nails"
echo "==============================================="
echo ""

cd $DIRPATH

#
# Do the image conversion
#

#
# Setting Default values
#
colcount=0
pagecount=0
pagenumber=1

for image in $SORT; do


        if [ $colcount -eq  $COUNT ]
                then
                echo "</tr><tr>" >> $DIRPATH/$PAGENAME
                colcount=1
        else
                colcount=$(expr $colcount + 1)
        fi

   
    if [ $pagecount =  $PERPAGE ]
        then
        echo "NEW PAGE"
        echo "</tr></table></center>" >> $DIRPATH/$PAGENAME
        if [ $pagenumber = "1" ]
            then
            echo "<table width=100% border=0 ><tr><td align=center ><a 
href="page2.html">Page 2 --></a></td></tr></table>" >> $DIRPATH/$PAGENAME
                echo "<center><font size=2 >Created with <a 
href=http://shawley.myip.org/projects/photogen.php> 
<b>Photo-gen</b></a></center>" >>  $DIRPATH/$PAGENAME
            echo "</body></html>" >> $DIRPATH/$PAGENAME

            pagenumber=2

            PAGENAME=page$pagenumber.html
                        echo "$PAGENAME"

            echo "<HTML><HEAD>" > $DIRPATH/$PAGENAME


            echo "<TITLE> $GALNAME Page 2</TITLE>" >> $DIRPATH/$PAGENAME
            echo "<SCRIPT TYPE=\"text/javascript\">" >> $DIRPATH/$PAGENAME
            echo "<!-- " >> $DIRPATH/$PAGENAME
            echo "function popup(mylink, windowname)" >> $DIRPATH/$PAGENAME
            echo "{" >> $DIRPATH/$PAGENAME
            echo "if (! window.focus)return true;" >> $DIRPATH/$PAGENAME
            echo "var href;" >> $DIRPATH/$PAGENAME
            echo "if (typeof(mylink) == 'string') " >> $DIRPATH/$PAGENAME
            echo "   href=mylink;" >> $DIRPATH/$PAGENAME
            echo "else " >> $DIRPATH/$PAGENAME
            echo "   href=mylink.href;" >> $DIRPATH/$PAGENAME
            echo "window.open(href, windowname, 
'width=$RESIZEH,height=$RESIZEV,scrollbars=yes');" >> $DIRPATH/$PAGENAME
            echo "return false;" >> $DIRPATH/$PAGENAME
            echo "}" >> $DIRPATH/$PAGENAME
            echo "//--> " >> $DIRPATH/$PAGENAME
            echo "</SCRIPT>" >> $DIRPATH/$PAGENAME

            echo "</HEAD><BODY bgcolor=$BGCOLOR>" >> $DIRPATH/$PAGENAME
            echo "<center><H1> $GALNAME - Page 
$pagenumber</H1></center>" >> $DIRPATH/$PAGENAME

            if [ $URL = "y" ] || [ $URL = "Y" ]
                   then
                echo "<center><font size=5><a href=$URLHOME >HOME</a> 
</center>" >> $DIRPATH/$PAGENAME
            fi


            if [ $TLPAGES -gt 1 ]
            then
            echo "<center><font size =5>PAGE: " >> $DIRPATH/$PAGENAME
            x=1
            until [ "$x" -gt $TLPAGES ]
                        do
                    if [ $x -eq 1 ]
                    then
                    echo "<a href=index.html>$x </a>" >> $DIRPATH/$PAGENAME
                    x=$(expr $x + 1)
                    else
                    echo "<a href=page$x.html>$x </a>" >> $DIRPATH/$PAGENAME
                    x=$(expr $x + 1)
                    fi
                    if [ $x -lt $TLPAGES ] || [ $x -eq $TLPAGES ]
                    then
                    echo " - " >>$DIRPATH/$PAGENAME
                    fi
            done
            echo "<p></font></center>" >>$DIRPATH/$PAGENAME

            fi

            echo "<center><table bgcolor=#CCCCC border=2  cellpadding=20 
cellspacing=2><tr>" >> $DIRPATH/$PAGENAME

            pagecount=0
            colcount=1
        else

            LINKPAGE=$(expr $pagenumber + 1)   
                        echo "<table width=100% border=0 ><tr><td 
align=center ><a href="page$LINKPAGE.html">Page $LINKPAGE 
--></a></td></tr></table>" >> $DIRPATH/$PAGENAME
                        echo "<center><font size=2 >Created with <a 
href=http://shawley.myip.org/projects/photogen.php> 
<b>Photo-gen</b></a></center>" >>  $DIRPATH/$PAGENAME

                        pagenumber=$(expr $pagenumber + 1)

                        echo "</body></html>" >> $DIRPATH/$PAGENAME

                        PAGENAME=page$pagenumber.html
                        echo "$PAGENAME"

                        echo "<HTML><HEAD><TITLE> $GALNAME Page 
$pagenumber </TITLE>" > $DIRPATH/$PAGENAME

            echo "<SCRIPT TYPE=\"text/javascript\">" >> $DIRPATH/$PAGENAME
            echo "<!-- " >> $DIRPATH/$PAGENAME
            echo "function popup(mylink, windowname)" >> $DIRPATH/$PAGENAME
            echo "{" >> $DIRPATH/$PAGENAME
            echo "if (! window.focus)return true;" >> $DIRPATH/$PAGENAME
            echo "var href;" >> $DIRPATH/$PAGENAME
            echo "if (typeof(mylink) == 'string') " >> $DIRPATH/$PAGENAME
            echo "   href=mylink;" >> $DIRPATH/$PAGENAME
            echo "else " >> $DIRPATH/$PAGENAME
            echo "   href=mylink.href;" >> $DIRPATH/$PAGENAME
            echo "window.open(href, windowname, 
'width=$RESIZEH,height=$RESIZEV,scrollbars=yes');" >> $DIRPATH/$PAGENAME
            echo "return false;" >> $DIRPATH/$PAGENAME
            echo "}" >> $DIRPATH/$PAGENAME
            echo "//--> " >> $DIRPATH/$PAGENAME
            echo "</SCRIPT>" >> $DIRPATH/$PAGENAME

            echo "<BODY bgcolor=$BGCOLOR>" >> $DIRPATH/$PAGENAME
                        echo "<center><H1> $GALNAME - Page 
$pagenumber</H1></center>" >> $DIRPATH/$PAGENAME

                        if [ $URL = "y" ] || [ $URL = "Y" ]
                        then
                        echo "<center><font size=5><a href=$URLHOME 
 >HOME</a> </center>" >> $DIRPATH/$PAGENAME
                        fi


                        if [ $TLPAGES -gt 1 ]
                        then
                        echo "<center><font size =5>PAGE: " >> 
$DIRPATH/$PAGENAME
                        x=1
                        until [ "$x" -gt $TLPAGES ]
                                do
                                if [ $x -eq 1 ]
                                then
                                echo "<a href=index.html>$x </a>" >> 
$DIRPATH/$PAGENAME
                                x=$(expr $x + 1)
                                else
                                echo "<a href=page$x.html>$x </a>" >> 
$DIRPATH/$PAGENAME
                                x=$(expr $x + 1)
                                fi
                                if [ $x -lt $TLPAGES ] || [ $x -eq 
$TLPAGES ]
                                then
                                echo " - " >>$DIRPATH/$PAGENAME
                                fi
                        done
                        echo "<p></font></center>" >>$DIRPATH/$PAGENAME
               
                        fi

                        echo "<center><table bgcolor=#CCCCC border=2 
cellpadding=20 cellspacing=2><tr>" >> $DIRPATH/$PAGENAME
           
            pagecount=0
            colcount=1

        fi
    fi
   
       
    echo "$(($pagecount + 1)) - Lowresing image:$image"
   
    if [ ! -e $DIRPATH/lowres/low-$image ]
        then
             if [ "$HIRES" = "y" ] || [ "$HIRES" = "Y" ]
            then
            echo "-- Converting original to 72 dpi --"
            convert -density 72x72 $DIRPATH/$image $DIRPATH/$image
            fi
             if [ "$RESIZE" = "y" ] || [ "$RESIZE" = "Y" ]
            then
            echo "-- Converting original to $RESIZEH x $RESIZEV --"
            convert -geometry $RESIZEHx$RESIZEV $DIRPATH/$image 
$DIRPATH/$image
            fi
        convert -density 72x72 -geometry $IMAGESIZE $DIRPATH/$image 
$DIRPATH/lowres/low-$image
    else
        echo "$(($pagecount + 1)) == Image low-$image is there - 
Skipping Lowres Generation =="
    fi

    if [ $CAPT = "y" ] || [ $CAPT = "Y" ]
        then
        if [ $XWIN = "y" ] || [ $XWIN = "Y" ]
            then
            display $DIRPATH/lowres/low-$image &
        fi
        echo "Please Enter Caption for Image"
        read imagecap
            if [ ! -e $DIRPATH/captions.txt ]
            then
            echo "Creating file to save captions"
            echo "$DIRPATH/captions.txt"
            touch $DIRPATH/captions.txt
            fi
        echo "$image :$imagecap" >> $DIRPATH/captions.txt

    elif [ $CAPTBACK = "y" ] || [ $CAPTBACK = "Y" ]
    then
        imagecap=`grep "$image" $DIRPATH/captions.txt |  cut -d ":" -f2`
        if [ "$imagecap" = "" ]
        then
        echo ""
        echo 
"-------------------------------------------------------------------------"
        echo "Can not find caption for this image [ $image ], please 
enter new caption."
        echo 
"-------------------------------------------------------------------------"
        echo ""
         read imagecap   
        echo "USING NEW CAPTION: $imagecap"
        echo "$image :$imagecap" >> $DIRPATH/captions.txt
        else
        echo "USING BACKUP CAPTION: $imagecap"
        fi
    else
        imagecap=$image
    fi
   
    pagecount=$(expr $pagecount + 1)   

    echo "<td align=center><a href=\"$image\" onClick=\"return 
popup(this, 'notes')\"><img border=2 
src=lowres/low-$image></a><br>$imagecap</td>" >> $DIRPATH/$PAGENAME
done
    echo "</tr></table></center>" >> $DIRPATH/$PAGENAME
 
    if [ $pagenumber -ne 1 ]
    then
        echo "<table width=100% border=0 ><tr><td align=center ><a 
href="$FIRSTPAGENAME">Go to First Page --></a></td></tr></table>" >> 
$DIRPATH/$PAGENAME
    fi

    echo "<center><font size=2 >Created with <a 
href=http://shawley.myip.org/projects/photogen.php> 
<b>Photo-gen</b></a></center>" >>  $DIRPATH/$PAGENAME
echo ""
if  [ $XWIN = "y" ] || [ $XWIN = "Y" ]
    then
    echo "Would you like to close the thumbnails on your screen? (y or n)"
    read KILL_DISPLAY
    if [ $KILL_DISPLAY = "y" ] || [$KILL_DISPLAY = "Y" ]
        then
        /usr/bin/killall display > /dev/null 2>&1
    fi
fi
#
#Move Good log file
#
mv $LOGFILE $DIRPATH/photogen.log
echo "===================================================================="
echo "Photo Album Has Been Generated"
echo "Please go to:"
echo "file:$DIRPATH$FIRSTPAGENAME"
echo "with your web browser to view"
echo "===================================================================="
echo "IF YOU HAVE ARCHIVED YOUR IMAGES, PLEASE PUT THEM IN A SAFE PLACE."
echo "IF YOU RUN PHOTOGEN AGAIN, AND CHOOSE TO ARCHIVE YOUR IMAGES,"
echo "YOU MAY REPLACE YOUR ORIGINALS WITH PICTURES PHOTOGEN HAS RE-RESED"
echo "OR RE-SIZED. PLEASE MOVE THE IMAGES TO A SAVE PLACE."
echo "===================================================================="
echo ""
echo ""
echo ""
exit 0

Matt Heavner wrote:

>Hi James and everyone,
>
>My digital camera takes jpegs but uses something close to 100% quality 
>settings.  The first thing I do when starting to put them on the web is 
>to change the images to 75% quality, and this drastically reduces the 
>file size (typically from > 1MB to < 100 kB for 1920x1600).  A script 
>that uses the perlmagick modules (with some other useful code commented 
>out) is attached.  I'm sure that this is mostly borrowed from somewhere 
>(maybe the perlmagick docs?), but I've forgotten where, so I can't give 
>proper credit..
>
>#!/usr/bin/perl -w
>
># Matt Heavner 2003/08/27
># go through a directory and save pictures w/ quality 75 setting
># It is written to look for *.JPG and save them as *.jpg
># The images can also be reduced by 50%, but that is commented out
>
>use Image::Magick;
>$ver = 0; #0 means don't be verbose...
>
>@files = `ls *.JPG`;
>
>foreach $file (@files) {
>   chop $file;
>   $file =~ /(\w+)\056JPG/;
>   $stub = $1;
>   if ($ver) { print "Stub is $stub\n";}
>
>   $image = Image::Magick->new;
>   $status = $image->Read($file);
>   warn "$status" if "$status";
>
>#  $status = $image->Resize(geometry=>"50%");
>#  warn "$status" if "$status";
>
># Use the 216 web-safe color cube
>#  $cube = Image::Magick->new;
>#  $status = $cube->Read('NETSCAPE:');
>#  warn "$status" if "$status";
>#  $image->Map($cube);
>
>   $status = $image->Write(filename=>"jpg:$stub.jpg",quality=>"75");
>   warn "$status" if "$status";
>
>   # Neatly dispose of our object
>   undef $image;
>}
>
>  
>

-- 
Browns Homepage (Bear video! - updated 10Jun2004) http://jdb.homelinux.net


------------------------------------
This is the Juneau-LUG mailing list.
To unsubscribe, send an e-mail to juneau-lug-request@xxxxxxxxxxxxx with the 
word unsubscribe in the subject header.

Other related posts: