<?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