Home php ImageTTFTEXT does not find the font

ImageTTFTEXT does not find the font

Author

Date

Category

When I prescribe the path to the font in the ImageTFFTEXT () function;
An ill-fated error

appears

imagettftext (); COULD NOT FIND / OPEN FONT

Code (PHP 7.2):

$ black = imagecolorallocate ($ im, 0, 0, 0);
$ font = "./arial.tff";
ImageTTFTEXT (ImageCreaTeeColor (400, 30), 20, 0, 10, 20, $ Black, $ font, "text");

How to fix it?


Answer 1, Authority 100%

from documentation :

In many cases, when the font is in the same directory as
PHP script will help the next trick.

& lt;? php
// Setting Variable Environment for GD
Putenv ('Gdfontpath ='. Realpath ('.'));
// Font name for use (Note that the extension .ttf is not specified)
$ font = 'somefont';

You can try to transfer the absolute path to the font:

$ font = realpath ('./ arial.ttf');

or

$ font = __dir __. '/ arial.ttf';

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions