PHP/GD:更好的高斯模糊 [英] PHP/GD : Better Gaussian blur

查看:229
本文介绍了PHP/GD:更好的高斯模糊的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用GD库来模糊图像,不幸的是GD提供的GAUSSIAN_BLUR效果还不够,我希望某些东西变得更模糊

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.

推荐答案

您可以尝试卷积:

$gaussian = array(array(1.0, 2.0, 1.0), array(2.0, 4.0, 2.0), array(1.0, 2.0, 1.0));
imageconvolution($image, $gaussian, 16, 0);

$gaussian是一个矩阵,因此从数学上来说是

$gaussian is a matrix, so mathematically it's

[[1, 2, 1],
 [2, 4, 2],
 [1, 2, 1]]

您可以在以下位置找到其他卷积过滤器: http://aishack.in/tutorials/image-convolution-examples/

you can find other convolution filters at: http://aishack.in/tutorials/image-convolution-examples/

imageconvolution( <image element>, <convolution matrix>, <divisor (sum of convolution matrix)>, <color offset>);

因此从1+2+1+2+4+2+1+2+1 = 16以上的代码中求出矩阵的和. http://www.php.net/manual/en/function. imageconvolution.php#97921 是获取 除数之和.

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.

签出 http://php.net/manual/en/function.imageconvolution .php 以获得有关此功能的更多信息.

check out http://php.net/manual/en/function.imageconvolution.php for more info on this function.

好的ol'时尚模糊是(1,2,1),(2,1,2),(1,2,1)

good ol' fashion blur is (1,2,1),(2,1,2),(1,2,1)

如下所述,您可以对结果输出多次运行任何过滤器,以增强效果.

as stated below you can run any filter more than once on the resulting output to also enhance the effect.

这篇关于PHP/GD:更好的高斯模糊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆