Return to Snippet

Revision: 763
at August 4, 2006 06:06 by mail_json


Initial Code
<?

/*this can be used to resize image in jpeg format only
which provive a good quality thumbnails*/
// This is the temporary file created by PHP

$uploadedfile = $_FILES['simage']['tmp_name'];

// Create an Image from it so we can do the resize
$src = imagecreatefromjpeg($uploadedfile);

// Capture the original size of the uploaded image
list($width,$height)=getimagesize($uploadedfile);
$newwidth=300;
//$newheight=($height/$width)*100;
$newheight=200;
$tmp=imagecreatetruecolor($newwidth,$newheight);

// this line actually does the image resizing, copying from the original
// image into the $tmp image
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);

// now write the resized image to disk. I have assumed that you want the
// resized, uploaded image file to reside in the ./images subdirectory.
$filename = $_FILES['simage']['name'];
imagejpeg($tmp,$filename,100);

imagedestroy($src);
imagedestroy($tmp);
?>

Initial URL
http://www.itwebinfo.com/forum/comments.php?DiscussionID=4&page=1#Item_0

Initial Description

                                

Initial Title
ITwebinfo.com - resizing jpeg image

Initial Tags

                                

Initial Language
PHP