<?
function resize_photo($tmp,$newname,$folder,$new_height){
$newname = strtolower($newname);
$arr_name = explode(".",$newname);
$lastname = $arr_name[sizeof($arr_name)-1];
// $newname = time().".".$lastname;
$file = getimagesize($tmp);
if ($file[1]>$new_height){
//copy($tmp,"photo/".$newname);
if ($lastname=="jpg" || $lastname=="jpeg"){
$file = getimagesize($tmp);
$newheight = $new_height;
$newwidth = round($newheight*$file[0]/$file[1]);
$newimage = imagecreatefromjpeg($tmp);
$imagex = imagesx($newimage);
$imagey = imagesy($newimage);
$image_fin =imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($image_fin,$newimage,0,0,0,0,$newwidth+1,$newheight+1,$imagex,$imagey);
imagejpeg($image_fin,$folder."/".$newname);
imagedestroy($newimage);
imagedestroy($image_fin);
}elseif ($lastname=="gif"){
$file = getimagesize($tmp);
$newheight = $new_height;
$newwidth = round($newheight*$file[0]/$file[1]);
$newimage = imagecreatefromgif($tmp);
$imagex = imagesx($newimage);
$imagey = imagesy($newimage);
$image_fin =imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($image_fin,$newimage,0,0,0,0,$newwidth+1,$newheight+1,$imagex,$imagey);
imagegif($image_fin,$folder."/".$newname);
imagedestroy($newimage);
imagedestroy($image_fin);
}
}else{
move_uploaded_file($tmp,$folder."/".$newname);
}
return $newname;
}
?>
ไม่มีความคิดเห็น:
แสดงความคิดเห็น