I am trying to create an image with text by using imagettftext. It is telling me Warning: imagettftext(): Invalid font filename in C:\xampp\htdocs\recentpost.php on line 32. Here is the code on line 32 I am using to add the text
imagettftext($img, 12, 0, 20, 1, $black, "../fonts/arial.ttf", "News!");
I copied the font right out of the C:/Windows/Fonts folder so it is a valid font.
Try something like:
$font = dirname(__FILE__) . '/arial.ttf';
//OR
$font = dirname(__FILE__) . '/fonts/arial.ttf';
imagettftext($img, 12, 0, 20, 1, $black, $font, "News!");
Hope it helps
Have you tried using
imagettftext($img, 12, 0, 20, 1, $black, "../fonts/arial.TTF", "News!");
instead? (.TTF instead of .ttf)
and @Fab, you can use both \ and / on windows.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With