homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Help With Php Resizing
How to resize image with php?

 12:06 am on Oct 2, 2007 (gmt 0)

Got the following code, however my question is how to resize an uploaded image. Say if its greater then 300 pixles then resize the image so the max length or width is no greater than 300. For example a 400 X 350 image would be resized to 300 X 250

$pic_size = $_FILES['pic']['size'];
$pic_type = $_FILES['pic']['type'];


//check to see if file of proper format
if (($pic_type=='image/gif' $pic_type=='image/jpeg' $pic_type=='image/jpg' $pic_type=='image/png') && $pic_size <=20000000 )

list($width, $height) = getimagesize($temp_pic_name);

if($width>300 height>300)
//begin resizing uploaded image

//copy image to dir
copy($temp_pic_name, "999.jpg") or die("could not copy");
echo 'pic uploaded';
echo $pic_size;

elseif ($pic_size>20000000)
echo 'sorry this image is too large';
echo 'You can only upload images of the following format Gif, Jpeg & Png';



 3:23 pm on Oct 2, 2007 (gmt 0)

The PHP manual page for the imagecopyresampled [php.net] function has an example of resampling an image proportionally that should meet your need.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved