[GLLUG] PHP/images/MySQL

Bruce Smith brucesmith@chartermi.net
04 Feb 2003 14:53:55 -0500


If you don't mind multiple copies (different sizes) of the same image on
your hard drive, you can shrink them all very easily by using a simple
little script and the ImageMagick commands.

Here's an example that will shrink multiple images to 18% of the
original size, and give the new/shrunk file a new name by adding 
a "s" right before ".jpg":

---------------------------------------------
#!/bin/sh
[ -z "$SHRINK" ] && SHRINK='18%'
echo "Shrinking to $SHRINK"
for f
do
        n=`echo $f | sed -e 's/.jpg/s.jpg/'`
        if [ -f "$n" ]; then
                echo "overwrite $n? (y/n)"
                read ans
                [ "$ans" = "y" ] || continue
        fi
        echo "creating:  $n"
        convert -geometry $SHRINK "$f" "$n"
done
---------------------------------------------

If the script name is "shrink", then run it like "shrink *jpg".

And it can easily be modified to shrink to a set resolution instead 
of a percentage.

I use it all the time to create thumbnails.  And I wrote a nice little
PHP script that reads the current directory and displays all the files
found in a thumbnail format for viewing . . .

 - BS

> In the past, I've used ImageMagick to perform the functions you are
> describing, so that everything is automated through the form, and all
> manipulation of images is done during initial upload / form processing.
> 
> Basically, you have your form, with all the user input you need
> contained in that form.  You'd also have a space for file upload fields
> (for your original images), however many you decide that you need.  When
> php processes the form, it can verify the type of file uploaded was an
> image (important step), then manipulate the image (resize, copy, etc.)
> as many times as you need to create your thumbnail / original image
> sets, then add / modify an entry in the database accordingly.  You could
> just name your files by upload time, split them up by directory or name
> (scaled_640_480_1044386407.jpg), and either store them in the database
> itself or just store their location in the database.
> 
> Difficult, and tedious, but not impossible.  I even have a working
> example that I'll sell you for a six-pack. ;)
> 
> --Brad Fears
> 
> 
> On Tue, 2003-02-04 at 13:21, Mike Szumlinski wrote:
> > Okay...here is what I'm trying to do and I can't figure out a good 
> > method.  Maybe someone else out there has a good idea on how to do this:
> > 
> > I have a user input through a form a bunch of random info (check boxes, 
> > text fields, etc), but I also need up to 4 images to correspond to the 
> > ID for that row.  Its for an inventory system.
> > 
> > The images also need to be thumbnailed and shrunk before they hit the 
> > folder/database (haven't figured out what is better yet). So basically 
> > each unique ID within the database has up to 8 images associated with 
> > it (4 thumbs, 4 640x480 images).
> > 
> > I can't quite think of how to pull it off.  I've done single image 
> > stores by just renaming the image the ID.jpg, but that won't work here. 
> >   I've thought about putting them into the table in the database, but I 
> > can't figure out how to use GD to shrink them down first if I do that.  
> > I'm sorta clueless on how to pull this off for now.  Any ideas?
> > 
> > -Mike