I am trying to use ImageTTF commands (ImageTTFBBox, ImageTTFText, ImagePNG etc.) to create a web counter.
The aim is that a user just needs to have a <img src = counter.php> tag, and a count graphic will appear.
This is my code so far;
<?
$fontbase = "/usr/share/fonts/ttf/";
$fontfile = $fontbase.$font;
if (!$angle)
{
$angle=0;
}
$size = ImageTTFBBox ($fontsize, $angle, $fontfile, $text);
$dx = max($size[2], $size[4]) - min($size[0], $size[6]);
//$dx = $dx + strlen($text);// extreme x values
$dy = max($size[1], $size[3]) - min($size[5], $size[7]);
//$dy = $dy + strlen($text); // extreme y values
$im = imagecreate ($dx, $dy);
$bkgc = ImageColorAllocate ($im, 255, 255, 255);
$txtc = ImageColorAllocate ($im, 197, 196, 230);
$baseline = $dy - max($size[1], $size[3]);
ImageTTFText ($im, $fontsize, $angle, 0, ($dy-max($size[1], $size[3])), $txtc, $fontfile, $text);
Header ("Content-type: image/png");
imagePNG ($im);
ImageDestroy ($im);
This works OKish, as it chops of little bits around the edges.
Does anyone have any suggested changes i can make, or failing that, a totally different way to get the same output.
TIA
Jamie