【发布时间】:2025-12-15 00:05:02
【问题描述】:
一段时间以来,我一直在尝试使用 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..
【问题讨论】:
-
某事告诉我
imageconvolution不会自动分配生成的颜色(灰色,介于黑色和白色之间)。您获得黑白结果的原因是因为它选择了与模糊像素值最相似的颜色。尝试使用imagecreatetruecolor创建图像。 (我评论而不是回答,因为我不确定而且我无法从这里进行测试。)
标签: php blur gaussian image-conversion