Question

I've been trying to blur some text for a while now using the following code in 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)

However the image does not blur, it only decreases in resolution, becoming grainy... Demo here..

Was it helpful?

Solution

Remove ImageColorTransparent($image, $background); to see the effect

Example

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

Output

enter image description here enter image description here

 ^ Before ^           ^ After ^
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top