0

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..

Andreas Jarbol
  • 745
  • 2
  • 11
  • 27
  • Something tells me the resulting colors (grey, somewhere in between black and white) are not automatically allocated by `imageconvolution`. The reason you get a black and white result is because it picks the most similar colors to the blurred pixel values. Try creating the image with [`imagecreatetruecolor`](http://www.php.net/manual/en/function.imagecreatetruecolor.php). (I commented instead of answered because I'm not sure and I'm not in the position to test from here.) – TaZ Oct 29 '12 at 00:11

1 Answers1

2

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 ^
Baba
  • 94,024
  • 28
  • 166
  • 217