PHP / GD高斯模糊效应 [英] PHP/GD Gaussian Blur Effect

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

问题描述

我需要使用PHP和GD对图像的某个区域进行模糊处理,目前我正在使用以下代码:

I need to obfuscate a certain area of an image using PHP and GD, currently I'm using the following code:

for ($x = $_GET['x1']; $x < $_GET['x2']; $x += $pixel)
{
    for ($y = $_GET['y1']; $y < $_GET['y2']; $y += $pixel)
    {
        ImageFilledRectangle($image, $x, $y, $x + $pixel - 1, $y + $pixel - 1, ImageColorAt($image, $x, $y));
    }
}

这基本上用$ pixel的正方形替换所选区域像素。我想完成某种模糊(高斯优选)效果,我知道我可以使用ImageFilter()函数:

This basically replaces the selected area with squares of $pixel pixels. I want to accomplish some kind of blur (gaussian preferably) effect, I know I can use the ImageFilter() function:

ImageFilter($image, IMG_FILTER_GAUSSIAN_BLUR);

但它模糊了整个画布,我的问题是我只是想模糊特定区域。 / p>

But it blurs the entire canvas, my problem is that I just want to blur a specific area.

推荐答案

您可以将图像的特定部分复制到新图像中,在新图像上应用模糊并将结果复制回来。

You can copy a specific part of the image into a new image, apply the blur on the new image and copy the result back.

这样排序:

$image2 = imagecreate($width, $height);
imagecopy  ( $image2  , $image  , 0  , 0  , $x  , $y  , $width  , $height);
imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR);
imagecopy ($image, $image2, $x, $y, 0, 0, $width, $height);

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

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