$dstw = $width / $height * $h;
$dstx = ($w - $dstw) / 2;
#第二步:E种情况 源宽 < 目标宽 源高 < 目标高
} else {
$srcx = 0;//源横坐标
$srcw = $width;//源宽
$srcy = 0;//源总坐标
$srch = $height;//源高
$dstx = ($w - $width) / 2;//目标图象的横坐标
$dstw = $width;//目标的宽
$dsty = ($h - $height) / 2;//目标图象的总坐标
$dsth = $height;//目标的高
}
$di = imagecreatetruecolor($w, $h);//创建一个真彩色的图象句柄
$bgc = imagecolorallocate($di, 255, 255, 255);//设置一个颜色
imagefilledrectangle($di, 0, 0 ,$w, $h, $bgc);//给图象句柄填充颜色,在这里也设置了图象句柄的宽与高
$test = imagecopyresampled($di, $bs, $dstx, $dsty, $srcx, $srcy, $dstw, $dsth, $srcw, $srch);//把源图象按各参数复制到目标图象中去,其实在此时处理的高高与宽是有变化的
if (GetFileExt($dst) == 'gif') {
imagegif($di, $dst);
} else {
imagejpeg($di, $dst, 90);
}
imagedestroy($di);
imagedestroy($bs);
} else {
#创建图象标识符失败,则直接进行按照参数长度进行缩略
$di = imagecreatetruecolor($w, $h);
$bgc = imagecolorallocate($di, 255, 255, 255);
imagefilledrectangle($di, 0, 0, $w, $h, $bgc);
if (GetFileExt($dst) == 'gif') {
imagegif($di, $dst);
} else {
imagejpeg($di, $dst, 90);
}
imagedestroy($di);
}
}
# 获取文件后缀名
function GetFileExt($dir) {
return trim(strtolower(substr($dir,strrpos($dir,'.')+1)));
}