<?php class image_blur{ function gaussian_blur($srcImg,$savepath=null,$savename=null,$blurFactor=3){ $gdImageResource=$this->image_create_from_ext($srcImg); $srcImgObj=$this->blur($gdImageResource,$blurFactor); $temp = pathinfo($srcImg); $name = $temp['basename']; $path = $temp['dirname']; $exte = $temp['extension']; $savename = $savename ? $savename : $name; $savepath = $savepath ? $savepath : $path; $savefile = $savepath .'/'. $savename; $srcinfo = @getimagesize($srcImg); switch ($srcinfo[2]) { case 1: imagegif($srcImgObj, $savefile); break; case 2: imagejpeg($srcImgObj, $savefile); break; case 3: imagepng($srcImgObj, $savefile); break; default: return '保存失敗'; //保存失敗 } return $savefile; imagedestroy($srcImgObj); } } $image_blur = new image_blur();
//blurFactor的值代表模糊程度,savepath為空時候直接覆蓋,savename為空直接用原名
$image_blur->gaussian_blur($srcImg="./5.jpg",$savepath=null,$savename=null,$blurFactor=5);
?>
這個方法百度到的,有個面試我的讓我做,百度了一堆資料才實現。
//blurFactor的值代表模糊程度
效果展示:
原圖
模糊程度2
模糊程度3
模糊程度4
模糊程度5
模糊程度6
模糊程度7