$filepath = $uf->getpath(). '/'. $self['stud_photo'] ;
$image_info = getImageSize($filepath);
$height_org = $image_info[1];
$width = $image_info[0];
if ($height_org>$width*1.25) {
//進行裁切
$crop = ($height_org-$width*1.25)/2;
$src = imagecreatefromstring(file_get_contents($filepath));
//裁剪區
$x = 0;
$y = $crop;
//寬和高
$height = $width*1.25;
//最终保存成寬和高, $final_width = 480;
$final_height = round($final_width * $height / $width);
//這是關鍵
$new_image = imagecreatetruecolor($final_width, $final_height);
imagecopyresampled($new_image, $src, 0, 0, $x, $y, $final_width, $final_height, $width, $height);
//輸出成檔案覆蓋掉原來的檔案
imagejpeg($new_image, $filepath);
}
}
沒有留言:
張貼留言