/**
* @param $imgsrc //图片地址 本地路径或者网络图片地址
* @param $imgdst //新图片保存路径
* 图片压缩
*
*/
public function compressedImage($imgsrc, $imgdst)
{
list($width, $height, $type) = getimagesize($imgsrc);
$new_width = $width>120 ? 120 : $width; //新图片比例这里设置了120X120
$new_height =$height > 120 ? 120 : $height;
$image_wp = imagecreatetruecolor($new_width, $new_height);
//type 为 1:gif动图 2:jpg/jpeg 3:png
if($type == 2){
$image = imagecreatefromjpeg($imgsrc);
}else{
$image = imagecreatefrompng($imgsrc);
}
imagecopyresampled($image_wp, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
//100代表的是质量、压缩图片容量大小
imagejpeg($image_wp, $imgdst, 100);
imagedestroy($image_wp);
imagedestroy($image);
}
最好调整下 尺寸比例 不要给的太小 不然会很糊。我用的120X120 效果来说还可以