PHP/GD:更好的高斯模糊
我想用 GD 库模糊图像,不幸的是 GD 提供的 GAUSSIAN_BLUR 效果还不够,我想要更模糊的东西,
<?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);
我想要这样的东西或至少接近它。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
遇到同样的问题后,我应用了相同的过滤器几次,每次都应用到先前“imagefilter”调用的结果资源。我得到了您正在寻找的“更模糊”效果。
例如:
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.:
您可以尝试卷积:
$gaussian
是一个矩阵,因此从数学上讲,您可以在以下位置找到其他卷积滤波器:http://aishack.in/tutorials/image-volving-examples/
所以从上面的代码
1+2+1+2+4+2+1+2+1 = 16
矩阵之和。 http://www.php.net/manual/en/function。 image卷积.php#97921 是一个获取除数之和。
查看 http://php.net/manual/en/function.imagevolvo.php< /a> 有关此功能的更多信息。
好的时尚模糊是 (1,2,1),(2,1,2),(1,2,1)
编辑:
如下所述,您可以对结果输出多次运行任何过滤器,以增强效果。
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 thesum 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.
试试这个:
try this:
我基于 this 解决方案:
当您在多次模糊后应用平滑时,它会提供非常好的模糊效果。您可以在代码中尝试使用以下数字:
25, 10, -7
。另请参阅: 如何测量用 PHP 编写的代码的速度
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
不确定 imagefilter 参数是否有帮助,但请检查一下。
或者,只需将图像过滤器应用于其结果几次???
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???
为了获得更好的速度,请使用 https://www.php.net/manual/ tr/function.imagick-gaussianblurimage.php
注意:您需要安装
Imagick
php 扩展(按照 此处例子
For better speed use https://www.php.net/manual/tr/function.imagick-gaussianblurimage.php
Note: You need to install
Imagick
php extention (follow install instructions from hereexample