首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP-GD:图像的模糊部分

PHP-GD:图像的模糊部分
EN

Stack Overflow用户
提问于 2013-11-21 15:30:58
回答 2查看 2.8K关注 0票数 1

我需要模糊掉图像的一部分。

我可以涂黑一部分,但我需要模糊这部分。

有没有人能举个例子说明如何让它工作?

EN

回答 2

Stack Overflow用户

发布于 2013-11-21 15:39:06

您必须应用image convolution (wiki)。

模糊的矩阵是:

PHP代码:

代码语言:javascript
复制
$gaussian = array(
    array(1.0, 2.0, 1.0),
    array(2.0, 4.0, 2.0),
    array(1.0, 2.0, 1.0)
);
imageconvolution($YOUR_IMAGE, $gaussian, 16, 0); // apply convolution

完整的示例:

代码语言:javascript
复制
<?php
// Informations for blur selection
$x = 180;
$y = 20;
$width = 200;
$height = 180;

$img1 = imagecreatefromjpeg('img1.jpg'); // load source
$img2 = imagecreatetruecolor($width, $height); // create img2 for selection

imagecopy($img2, $img1, 0, 0, $x, $y, $width, $height); // copy selection to img2

$gaussian = array(
    array(1.0, 2.0, 1.0),
    array(2.0, 4.0, 2.0),
    array(1.0, 2.0, 1.0)
);
imageconvolution($img2, $gaussian, 16, 0); // apply convolution to img2

imagecopymerge($img1, $img2, $x, $y, 0, 0, $width, $height, 100); // merge img2 in img1

// Show result (img1)
header('Content-Type: image/jpg');
imagejpeg($img1);

imagedestroy($img1);
imagedestroy($img2);

如果你使用png或gif (参见php man),别忘了用正确的函数重命名imagecreatefromjpegimagejpeg

票数 4
EN

Stack Overflow用户

发布于 2013-11-21 15:40:23

或者你也可以使用imagefilterhttp://php.net/manual/en/function.imagefilter.php

代码语言:javascript
复制
imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20114956

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档