Welcome to WebmasterWorld Guest from 54.159.179.132

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Help With Php Resizing

How to resize image with php?

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

10+ Year Member



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';
}
}

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

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

Featured Threads

Hot Threads This Week

Hot Threads This Month