php等比例缩放图片及剪切图片代码分享
php等比例缩放图片及剪切图片代码分享 $ratio_orig){
$target_width = $target_height * $ratio_orig;
}else{
$target_height = $target_width / $ratio_orig;
}
}
switch ($source_mime){
case 'image/gif':
$source_image = imagecreatefromgif($source_path);
break;
} 用法:
剪切图片为固定大小:// 源图过高 if ($source_ratio > $target_ratio){ $cropped_width = $source_width; $cropped_height = $source_width * $target_ratio; $source_x = 0; $source_y = ($source_height - $cropped_height) / 2; }elseif ($source_ratio < $target_ratio){ // 源图过宽 $cropped_width = $source_height / $target_ratio; $cropped_height = $source_height; $source_x = ($source_width - $cropped_width) / 2; $source_y = 0; }else{ // 源图适中 $cropped_width = $source_width; $cropped_height = $source_height; $source_x = 0; $source_y = 0; } switch ($source_mime){
} $target_image = imagecreatetruecolor($target_width,$target_height); // 裁剪 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |