I\'m using imagettftext to make a bar graph and at the top of each bar I want to put the value.
I have the fol
Do it like this. Remember to place the font file "arial.ttf" in current directory:
0)
{
$drawsize = $size - 1;
$drawX = $x1 + $lastdifference / 2;
break;
}
$lastdifference = $maxwidth - $width;
}
$size--;
imagettftext($im, $drawsize, 0, $drawX, $y1 - 2, $allocatedcolor, $font, $text);
}
// Output to browser
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>
It uses imagettfbbox
function to get width of the text, then loops over the font size to get correct size, centers it and displays it.
So, it outputs the following: