![]() |
|
首页 │ Apache │ Linux│ Java│ MySQL│ 注册│帮助 | |||
[PHP]<?
function resize_image($image,$max_width=110,$max_height=90)
{
$size = getimagesize($image);
$width = $size[0];
$height = $size[1];
$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;
if ( ($width <= $max_width) && ($height <= $max_height) ) {
$tn_width = $width;
$tn_height = $height;
}
else if (($x_ratio * $height) > $max_height) {
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;
}
else {
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}
$src = imagecreatefromjpeg($image);
$dst = imagecreate($tn_width,$tn_height);
imagecopyresized($dst, $src, 0, 0, 0, 0, $tn_width,$tn_height,$width,$height);
$path = dirname($image).'/';
$filename = date('YmdHis');
$ext = '.jpg';
$filefullname = $filename . $ext;
$i = 0;
while (is_file($path . $filefullname))
$filefullname = $filename . $i++ . $ext;
imagejpeg($dst, $path . $filefullname,100);
return $path . $filefullname;
}
?> [/PHP]
这是一个调整图片大小的函数,可是我得到图片的颜色都变了,这个是针对jpg 的png 也是这样,但是gif的就不会,得到的图片颜色都很正常,可是因为要支持这三个格式,特别jpg的用的最多,大家帮忙在自己机上测试一下是怎么样,看看有没有办法,是我这出了问题,还是gd就这样了没救了

