问题
I've been looking for PHP code to apply a Gaussian blur to images.
What I've done was like this:
<?php
$image = imagecreatefromjpeg('new.jpg');
imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR);
imagejpeg($image, 'blur.jpeg');
imagedestroy($image);
?>
However the effect is very weak, and if I repeat the blur effect, it takes a very long time to process and the end result is still not that good.
I also used Timthumb , I always liked its simplicity, but it crops the image by default and its blurring effect is very weak.
回答1:
You can use ImageMagic
Original Image

Run via exec
convert a.png -blur 0x3 a_blur.png
OR Run
convert a.png -blur 0x8 a_blur.png

回答2:
It is possible also without ImageMagic lib;
header('Content-Type: image/png');
$blurs = 10;
$image = imagecreatefrompng('blur.png');
for ($i = 0; $i < $blurs; $i++) {
imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR);
}
imagepng($image, 'blur10.png');
imagedestroy($image);
After 10 blur applied;

回答3:
Image optimization is very heavy process so personally if i have these kind of task in PHP then i use this PHP Image Library Called PhpThumb it can create blur images without any code you just need to call it's script via url and provide parameters according to its docs check it's demo.
来源:https://stackoverflow.com/questions/14428257/how-to-achieve-a-blur-effect-in-php