bobthebullet990 Posted September 1, 2006 Share Posted September 1, 2006 Hi!!! Thanks for your time!!! ...I have created a php script that allows users to upload images to my webserver and then displays all images within the gallery! ...The thumbnails are resized proportionally, with a max size of 150x150px, however, i want to resize the main image if its larger than 500px to proportionally resize it to a size within 500x500px square! ...Is there no simple way to do this other than the way that i have done.... [code] // CLEAR THE FILENAME - IN CASE OF MULTIPLE UPLOADS, DON'T WANT AN ERROR! unset($thefilename); // CHECK THAT THERE IS A FILE TO UPLOAD if(!isset($_FILES) && isset($HTTP_POST_FILES)){ $_FILES = $HTTP_POST_FILES; } if(!isset($_FILES['fileToUpload'])){ $message .= "ERROR: The image entered was not found!<br>"; } $thefilename = basename($_FILES['fileToUpload']['name']); if(empty($thefilename)){ $message = "ERROR: The name of the file was not found."; } if(empty($error)) { $imagePath = $uploadDir . $thefilename; $result = @move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $imagePath); if(empty($result)) $message .= "ERROR: could not save the file!<br>"; // CREATE IMAGE THUMBNAIL $thumb = $thefilename; $handle = @imagecreatefromjpeg($imagePath); $x=imagesx($handle); $y=imagesy($handle); if($x > $y){ $max = $x; $min = $y; } if($x <= $y){ $max = $y; $min = $x; } // $size_in_pixel : The maximum value (in pixels) that the thumbnail width or height is allowed. $size_in_pixel = '150'; // CREATE WIDTH AND HEIGHT VALUES FOR THE THUMBNAIL - PROPORTIONAL TO ORIGINAL WIDTH AND HEIGHT RATIO. $rate = $max/$size_in_pixel; $final_x = $x/$rate; $final_y = $y/$rate; if($final_x > $x) { $final_x = $x; $final_y = $y; } $final_x = ceil($final_x); $final_y = ceil($final_y); $black_picture = imageCreatetruecolor($final_x,$final_y); imagefill($black_picture,0,0,imagecolorallocate($black_picture, 255, 255, 255)); imagecopyresampled($black_picture, $handle, 0, 0, 0, 0,$final_x, $final_y, $x, $y); $thumbPath = $thumbDir.$thumb; if(!@imagejpeg($black_picture, $thumbPath, $size_in_pixel)) imagestring($black_picture, 1, $final_x-4, $final_y-8, ".", imagecolorallocate($black_picture,0,0,0)); // DELETE ALL TEMPORARY IMAGE DATA imagedestroy($handle); imagedestroy($black_picture); }[/code] Quote Link to comment Share on other sites More sharing options...
jpratt Posted September 1, 2006 Share Posted September 1, 2006 see my post a few minutes ago labeled "image resize function an implementation" this show an easy function for resizing on the fly. Quote Link to comment Share on other sites More sharing options...
bobthebullet990 Posted September 1, 2006 Author Share Posted September 1, 2006 I want to image resize and save the resized image, not the original size image! I don't want to have 500kb images [1280x1024 and larger] clogging up my server!!!!!!!!! and then resize them in another script just to view it!!! ...to me, that just seems a waste of processing time and disc space! why resize an image every time when you can resize and save it at the resized size!!!...Check out my test version of the page; running on WAMP direct fom my PC! ...hopefully you will understand where i am comming from!!!http://82-32-189-3.cable.ubr07.azte.blueyonder.co.uk/WWW/gallery.php Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.