แสดงบทความที่มีป้ายกำกับ Webdesign แสดงบทความทั้งหมด
แสดงบทความที่มีป้ายกำกับ Webdesign แสดงบทความทั้งหมด

วันพุธที่ 24 กรกฎาคม พ.ศ. 2556

Resize images using PHP

if ($ext =="jpg" or $ext =="jpeg") {
$ori_img = imagecreatefromjpeg($photo);
} else if ($ext =="png") {
$ori_img = imagecreatefrompng($photo);
} else if ($ext =="gif") {
$ori_img = imagecreatefromgif($photo);
}

$ori_size = getimagesize($photo);
$ori_w = $ori_size[0];
$ori_h = $ori_size[1];
  if($ori_w >720)
  {
if ($ori_w>=$ori_h) {
$new_w = 720;
$new_h = round(($new_w/$ori_w) * $ori_h);
} else {
$new_h =720;
$new_w = round(($new_h/$ori_h) * $ori_w);
}
$new_img= imagecreatetruecolor($new_w, $new_h);
imagecopyresized( $new_img, $ori_img,0,0,0,0,$new_w, $new_h,$ori_w,$ori_h);

if ($ext =="jpg" or $ext =="jpeg") {
imagejpeg($new_img,"../images/$filename");
} else if ($ext =="png") {
imagepng($new_img,"../images/$filename");
} else if ($ext =="gif") {
imagegif($new_img,"../images/$filename");
}

imagedestroy($ori_img);
imagedestroy($new_img);
}