I want to blur an image with GD library, unfortunately the GAUSSIAN_BLUR effect that GD gives isn't enough and i want something being more blurrish
<?php $im = imagecreatefrompng($_GET['image']);
if($im && imagefilter($im, IMG_FILTER_GAUSSIAN_BLUR))
{
header('Content-Type: image/png');
imagepng($im);
}
else
{
echo 'fail';
}
imagedestroy($im);
I want something like this or at least near it.
You can try convolution:
$gaussian
is a matrix, so mathematically it'syou can find other convolution filters at: http://aishack.in/tutorials/image-convolution-examples/
so from the code above
1+2+1+2+4+2+1+2+1 = 16
the sum of the matrix. http://www.php.net/manual/en/function.imageconvolution.php#97921 is a neat trick for getting the sum of the divisor.check out http://php.net/manual/en/function.imageconvolution.php for more info on this function.
good ol' fashion blur is (1,2,1),(2,1,2),(1,2,1)
EDIT: as stated below you can run any filter more than once on the resulting output to also enhance the effect.
After coming across the same problem, I applied the same filter a few times, and each time to the resulting resource of the previous "imagefilter" call. I got the 'more blurry' effect you're looking for.
e.g.:
Not sure if the imagefilter arguments help but check them out.
Alternatively, simply apply the image filter to it's result a couple of times???
try this:
I have very good result with following code based on this solution:
When you apply smooth after several blurs it delivers very good blurry effect. You can experiment with the following number in the code:
25, 10, -7
.See also: How to measure the speed of code written in PHP