Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP imagettftext invalid font filename

Tags:

php

truetype

gd

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.

like image 728
legobear154 Avatar asked Jun 13 '12 04:06

legobear154


2 Answers

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

like image 187
Sudhir Bastakoti Avatar answered Nov 20 '22 07:11

Sudhir Bastakoti


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.

like image 1
Sebr Avatar answered Nov 20 '22 08:11

Sebr