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