我需要模糊掉图像的一部分。
我可以涂黑一部分,但我需要模糊这部分。
有没有人能举个例子说明如何让它工作?

发布于 2013-11-21 15:39:06
您必须应用image convolution (wiki)。
模糊的矩阵是:

PHP代码:
$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完整的示例:
<?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),别忘了用正确的函数重命名imagecreatefromjpeg和imagejpeg。
发布于 2013-11-21 15:40:23
或者你也可以使用imagefilter:http://php.net/manual/en/function.imagefilter.php
imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR)https://stackoverflow.com/questions/20114956
复制相似问题