Log in

View Full Version : Glowing text GD



shachi
03-15-2008, 08:44 PM
Hello everyone!

Can anyone create this: http://cbimg6.com/tutorials/08/02/11/1017ab.png

effect using php and gd? The fonts must be customizable and the background transparent.

Here's as far as I could get:



<?
function Blur(&$gdimg, $radius=0.5) {
// Taken from Torstein Hønsi's phpUnsharpMask (see phpthumb.unsharp.php)

$radius = round(max(0, min($radius, 50)) * 2);
if (!$radius) {
return false;
}

$w = ImageSX($gdimg);
$h = ImageSY($gdimg);
if ($imgBlur = ImageCreateTrueColor($w, $h)) {
// Gaussian blur matrix:
// 1 2 1
// 2 4 2
// 1 2 1

// Move copies of the image around one pixel at the time and merge them with weight
// according to the matrix. The same matrix is simply repeated for higher radii.
for ($i = 0; $i < $radius; $i++){
ImageCopy ($imgBlur, $gdimg, 0, 0, 1, 1, $w - 1, $h - 1); // up left
ImageCopyMerge($imgBlur, $gdimg, 1, 1, 0, 0, $w, $h, 50.00000); // down right
ImageCopyMerge($imgBlur, $gdimg, 0, 1, 1, 0, $w - 1, $h, 33.33333); // down left
ImageCopyMerge($imgBlur, $gdimg, 1, 0, 0, 1, $w, $h - 1, 25.00000); // up right
ImageCopyMerge($imgBlur, $gdimg, 0, 0, 1, 0, $w - 1, $h, 33.33333); // left
ImageCopyMerge($imgBlur, $gdimg, 1, 0, 0, 0, $w, $h, 25.00000); // right
ImageCopyMerge($imgBlur, $gdimg, 0, 0, 0, 1, $w, $h - 1, 20.00000); // up
ImageCopyMerge($imgBlur, $gdimg, 0, 1, 0, 0, $w, $h, 16.666667); // down
ImageCopyMerge($imgBlur, $gdimg, 0, 0, 0, 0, $w, $h, 50.000000); // center
ImageCopy ($gdimg, $imgBlur, 0, 0, 0, 0, $w, $h);
}
// imagepng($imgBlur, "imgBlur.png");
// imagepng($gdimg, "gdimg.png");
return true;
}
return false;
}

$im = imagecreatetruecolor(500, 500);
imagealphablending($im, false);
$col = imagecolorallocatealpha($im, 255, 255, 255, 127);
imagefilledrectangle($im, 0, 0, 500, 500, $col);
imagealphablending($im, true);

$font = "AnkeCalligraph.TTF";
$size = 100;
$textcolor = imagecolorallocate($im, 0, 0, 0);
imageTTFText($im, $size, 0, 100, 300, $textcolor, $font, "Test");
Blur($im, 20);
$textcolor = imagecolorallocate($im, 255, 255, 255);
imageTTFText($im, $size, 0, 100, 300, $textcolor, $font, "Test");

header("Content-Type: image/png");
imagealphablending($im, false);
imagesavealpha($im, true);
imagepng($im);
?>


However this is extremely resource intensive and doesn't produce a transparent bg. Any help is greatly appreciated!

Master_script_maker
03-16-2008, 01:56 AM
i don't believe there is a way to create transparentcy in php

shachi
03-16-2008, 07:56 AM
I bet there is because I did it on the same script. http://www.bl0g.co.uk/070327/Creating_Transparent_PNG_Images_in_GD/

alexjewell
03-16-2008, 12:58 PM
Try looking here:
http://www.php.net/imagecolortransparent
http://www.php.net/imagesavealpha

One thing you have to remember, though, is IE's limited support of transparency, especially in anything less than 5.5

shachi
03-16-2008, 03:10 PM
alexjewell: Been there, done that.

andrewgjohnson
03-20-2013, 03:45 AM
shachi,

I was having the same issue and wrote a function called imagettftextblur to address it, I've released it as open source at https://github.com/andrewgjohnson/imagettftextblur