function imgReSize($url,$prefix='s_',$width=80,$height=60)
{
$arrResult=array ('result'=>false,'tempurl'=>'','msg'=>'压缩图片失败!');
if(!file_exists($url)){
$arrResult['msg'] ="原始文件 ". $url." 不存在!";
return $arrResult;
}
$urlinfo=pathinfo($url);
$ext=strtolower($urlinfo['extension']);
$tempurl=$urlinfo['dirname'].'/'.$prefix.$urlinfo['basename'];
if (!preg_match('/^(gif|jpg|jpeg)$/',$ext)) {
$arrResult['msg'] ="图片格式不是gif或者jpg!";
return $arrResult;
}
list($actualWidth,$actualHeight) = getimagesize($url);
if ($actualWidth && ($actualWidth < $actualHeight)) {
$width=($height / $actualHeight) *$actualWidth;
} else {
$height=($width/ $actualWidth) *$actualHeight;
}
$tempimg=imagecreatetruecolor($width, $height);
if($ext=='gif'){
$img = imagecreatefromgif($url);
imagecopyresampled($tempimg, $img, 0, 0, 0, 0, $width, $height, $actualWidth, $actualHeight);
$arrResult['result']=imagegif($tempimg, $tempurl, 80);
}
else
{
$img=imagecreatefromjpeg($url);
imagecopyresampled($tempimg, $img, 0, 0, 0, 0, $width, $height, $actualWidth, $actualHeight);
$arrResult['result']=imagejpeg($tempimg, $tempurl, 80);
}
imagedestroy($tempimg);
imagedestroy($img);
if(file_exists($tempurl)){
$arrResult['tempurl']=$tempurl;
}else {
$arrResult['tempurl']=$url;
}
return $arrResult;
}