I am trying to generate images containing data from my database, and I want to use a custom font for it, so I looked up the imagettftext
. I am following its syntax, but it's not printing anything. What am I doing wrong?
When I use imagestring
it works fine. But that does not use any custom font.
I have placed my font.tff
file in the same folder as my script. Here is my code:
header('Content-Type: image/png');
$image = @imagecreate(400, 110);
$backgrund = imagecolorallocate($image, 70, 130, 180);
$textcolor = imagecolorallocate($image, 255, 255, 255);
$font = 'font.ttf';
// TTF
imagettftext($image, 10, 0, 15, 15, $textcolor, $font, 'Test TTF');
// Normal text
imagestring($image, 2, 15, 30, 'Test Normal Font', $textcolor);
imagepng($image, 'images/test.png');
imagedestroy($image);
Am I missing something? The first line is completely blank. I also tried adjusting the font size (it maybe is different than regular imagestring?) but still nothing. The font is a .ttf
font file.