$RESIZEWIDTH = 176; // 生成图片的宽度
$src = 'images/open1.jpg'; //原图片地址
function make_small_copy($src, $max_width) {
$dir = substr($src, 0, strrpos($src, '/') + 1);
$small_img = 'small_'.substr($src,strrpos($src,'/') + 1);
$data = getimagesize($src);
switch($data[2]){
case 1:
$im = @imagecreatefromgif($src);
break;
case 2:
$im = @imagecreatefromjpeg($src);
break;
case 3:
$im = @imagecreatefrompng($src);
break;
}
$width = $data[0];
$height = $data[1];
if($max_width < $width) {
$new_width = $max_width;
$new_height = $height*$max_width/$width;
if(function_exists("imagecopyresampled")) { //解决图片失真
$new_im = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($new_im, $im, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
} else {
$new_im = imagecreatetruecolor($new_width, $new_height);
imagecopyresized($new_im, $im, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
}
imagegif($new_im, $dir.$small_img);
imagedestroy($new_im);
} else {
imagegif($im, $dir.$small_img);
}
return $small_img;
}
注:改程序限制高度,等比例缩小。