Got it, It is not finished yet, still working on it.
But the basics work in this solution: (create transparent image, with antialias text & dropshadow in steps)
Code: Select all
<?php
create_bannertext();
/*
* Start function
**************************************************/
function create_bannertext($text="Florida rentals", $typeface="arial.ttf", $textcolor="FFF", $shadowcolor="000", $shadowdistance=8)
{
$fontfile = "font/";
$font = $fontfile.$typeface;
$h = 20;
$ypad = 5;
list($r1,$g1,$b1) = hex2rgb($textcolor);
list($r2,$g2,$b2) = hex2rgb($shadowcolor);
render_banner($h, $text, $font, $shadowdistance, $r1, $g1, $b1, $r2, $g2, $b2);
}
/*
* Convert short (3) or long (6) hex to RGB value
**************************************************/
function hex2rgb($color)
{
$color = str_replace('#','',$color);
$s = strlen($color) / 3;
$rgb[]=hexdec(str_repeat(substr($color,0,$s),2/$s));
$rgb[]=hexdec(str_repeat(substr($color,$s,$s),2/$s));
$rgb[]=hexdec(str_repeat(substr($color,2*$s,$s),2/$s));
return $rgb;
}
function calculate_shadowtransparency($i, $shadowdistance)
{
if ($i == 1)
{
return 0;
}
else
{
$steps = floor(127 / $shadowdistance);
$strength = 0 + ($steps * $i);
return $strength;
}
}
function render_banner($h, $text, $font, $shadowdistance, $r1, $g1, $b1, $r2, $g2, $b2)
{
$size = imageTTFBBox($h+$shadowdistance, 0, $font, $text);
$image = imageCreateTrueColor(abs($size[2]) + abs($size[0]), abs($size[7]) + abs($size[1]) + 20);
imageSaveAlpha($image, true);
ImageAlphaBlending($image, true);
$textcolor = imagecolorallocate($image, $r1, $g1, $b1);
//$shadowcolor = imagecolorallocate($image, $r2, $g2, $b2);
$tlo = imagecolorallocatealpha($image, 220, 220, 220, 127);
imagefill($image, 0, 0, $tlo);
if (is_numeric($shadowdistance) && $shadowdistance >= 1 && $shadowdistance <=10)
{
for ($i=0; $i < $shadowdistance; $i++)
{
$shadowtransparency = calculate_shadowtransparency($i, $shadowdistance);
$shadowcolor = imagecolorallocatealpha($image, $r2, $g2, $b2, $shadowtransparency);
imagettftext($image, $h, 0, 0+$i, abs($size[5])+$i, $shadowcolor, $font, $text);
}
}
imagettftext($image, $h, 0, 0, abs($size[5]), $textcolor, $font, $text);
imagepng($image, "output.png");
imagedestroy($image);
}
?>