At 04:52 PM 8/13/2002 +0200, Sascha Braun wrote:
Okay... I've looked at that library and felt as if I was looking into the
ark of the Covenant.
I'm really not that good at programing and looking at that script made my
This is a script I've used to save an image and then dynamically resize it
proportionately until it is within 200x180. It also renames the file and
creates a mysql database entry for the file so my image collection can
later be searched.
//Query Database to get the next sequential image number
$lastnumQry = SELECT imageID FROM images ORDER BY imageID DESC;
$lastnumRslt = mysql_query($lastnumQry, $conn);
$lastnum = mysql_fetch_array($lastnumRslt);
$newnum = $lastnum['imageID']+1;
//Set image directory root
$image_root = $DOCUMENT_ROOT.'/images/';
//Create a temp image file from uploaded jpeg
$tempimage = imagecreatefromjpeg($f_image);
//Get dimensions of image
$temp_h = ImageSY($tempimage);
$temp_w = ImageSX($tempimage);
//Checks that the image is not too small (less than 50x50)
if($temp_h 50 $temp_w 50)
echo ERROR: Image is less then 50x50.;
//set file name
$filename = $newnum.'.jpg';
echo ERROR: Image unable to save file. Try again later.;
//set file name for thumbnail
$smallfilename = $newnum.'_t.jpg';
//Check to see if the image is already within the 200x180 range
if($temp_h 200 $temp_w 180)
echo ERROR: Thumbnail Image unable to upload!;
This section of the script uses the math that to resize an image
You must cross multiply the dimensions with their ratios... I use
1.8 and 2.0
but I could of as easily used 180 and 200. The math works, I
don't know how
to really explain it, but it works.
echo Resize beginning.BR;
$ratio = $temp_w/$temp_h;
$dest_w = 200*$ratio;
$dest_h = 200;
$ratio = $temp_h/$temp_w;
echo Ratio - $ratio br;
$dest_w = 180;
$dest_h = 180*$ratio;
//On the off chance that the image is proportionate to 200x180
already we just set the height and width.
if(($temp_h*1.8) == ($temp_w*2))
$dest_w = 180;
$dest_h = 200;
//Create the canvas. To use imagecreatetruecolor you need
php_gd2.dll listed as an extension
$image_t = imagecreatetruecolor($dest_w, $dest_h);
//Resize (technically resample) the image to the new canvas
imagecopyresampled($image_t, $tempimage, 0, 0, 0, 0, $dest_w,
$dest_h, $temp_w, $temp_h);
//Save the Thumbnail
echo ERROR: Thumbnail Image unable to Upload!;
//Insert File info into MySQL database
$imageUpdate = insert into images (catID, caption, descr, systemID,
genreID, game) values ('$f_imageCat', '$f_caption', '$f_descr',
'$f_system', '$f_genre', '$f_game');
echo ERROR: Unable to Submit information to Database, try Upload
echo BRBRfont size=3Image Upload Successful! Image ID is: $newnum;
META HTTP-EQUIV=REFRESH CONTENT=5;URL=image_form.php
I am running a windows system, so I know that the JPEG functions do work.
Gif functions will NOT WORK as the compression algorithm is now copyrighted.
If this script (once tweaked for your system needs) does not work and your
php.ini file is included the proper extension I don't know what to say.
I believe the jpeg funnktions don't work on a windows system. The Gifs don't
do either because they aren't implemeted too.
Please look at this Library. It's very nice but I don't get it working and
the guy who made it don't know either, why it's not working on my system.
Must be something about jpeg librarys and so on.
PS.: Examples at the end of the file.
Von: Nicholas Mercier [mailto:[EMAIL PROTECTED]]
Gesendet: Dienstag, 13. August 2002 10:35
An: [EMAIL PROTECTED]
Betreff: Re: [PHP] image function
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php