高斯模糊与图像卷积

时间:2012-10-28 23:56:15

标签: php blur gaussian image-conversion

我一直在尝试使用PHP中的以下代码模糊一些文本:

$image = imagecreate(150,25);
$background = ImageColorAllocate($image, 255, 255, 255);
$foreground = ImageColorAllocate($image, 0, 0, 0);

ImageColorTransparent($image, $background);
ImageInterlace($image, false);

ImageTTFText($image, 20, 0, 0, 20, $foreground, "font.ttf", "some text");

$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);

imagePNG($image)

然而,图像不会模糊,只会降低分辨率,变得颗粒状...... Demo here..

1 个答案:

答案 0 :(得分:2)

删除ImageColorTransparent($image, $background);以查看效果

示例

$image = imagecreate(150,25);
$background = ImageColorAllocate($image, 255, 255, 255);
$foreground = ImageColorAllocate($image, 0, 0, 0);

ImageInterlace($image, false);
ImageTTFText($image, 20, 0, 0, 20, $foreground, "verdana.ttf", "some text");

$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);

header('Content-Type: image/png');
imagepng($image, null, 9);

输出

enter image description here enter image description here

 ^ Before ^           ^ After ^