homepage Welcome to WebmasterWorld Guest from 54.242.231.109
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?
BlackRaven




msg:3466507
 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

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

if(is_uploaded_file($temp_pic_name))
{

//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

}
else
{
//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';
}
else
{
echo 'You can only upload images of the following format Gif, Jpeg & Png';
}
}

 

coopster




msg:3467108
 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