<div style='background-color: none transparent;'></div>
Home » » image resize in php

image resize in php





Untitled Document




if(!empty($_FILES['image1']['name'])) {
$imagelarge = $_FILES['image1']['tmp_name'];
$imagelargemain = $_FILES['image1']['name'];
$pathInfo = pathinfo($imagelargemain);
$rand = rand(1, 100000000000000);
$name = $rand . '.' . $pathInfo['extension'];
$src = imagecreatefromjpeg($imagelarge);
list($width,$height)=getimagesize($imagelarge);
if ($width > $height) {
$newwidth=600;
$newheight=($height/$width)*$newwidth;
}
elseif ($height > $width) {
$newheight=400;
$newwidth=($width/$height)*$newheight;
}
$center_x = (600/2)-($newwidth/2);
$center_y = (400/2)-($newheight/2);
$tmp=imagecreatetruecolor(600,400);
$white = imagecolorallocate($tmp, 255, 255, 255);
imagefill($tmp, 0, 0, $white);
imagecopyresampled($tmp,$src,$center_x,$center_y,0,0,$newwidth,$newheight,$width,$height);
$filename = WEB_UPLOAD."images/adverts/". $name;
imagejpeg($tmp,$filename,100);
imagedestroy($src);
imagedestroy($tmp);
$image_sql = mysql_query("UPDATE `adverts` SET image1 ='".$name."' WHERE id='".$advert_id."'") or die ("Error updating database");
}





Share this article :
 
Copyright © 2011. B.Sc B.Tech MCA Ploytechnic Mini,Main Projects | Free Main Projcets Download | MCA |B.tech . All Rights Reserved
Company Info | Contact Us | Privacy policy | Term of use | Widget | Advertise with Us | Site map
Template Modify by Creating Website. Inpire by Darkmatter Rockettheme Proudly powered by Blogger