Jump to content
TNG Community

imagettftext(): Could not find/open font in PHP 7.1.26 +


Ken Roy

Recommended Posts

On my WampServer 3.1.7 64-bit version running on Windows 10 Home (laptop) or on Windows 7 Pro (desktop), I am getting following errors

Quote

PHP Warning:  imagettftext(): Could not find/open font in D:\wamp64\www\tng\title.php on line 154

when I switch to use PHP 7.2 or 7.3 on WampServer.  The code works fine on ICDSoft PHP 7.2.13 site

Best I can tell the difference is the

FreeType Version     2.9.1    on WampServer with PHP 7.1.26 or higher versus    2.7.0 in PHP 5.6

ICDSoft is using FreeType Version 2.6.3 for their PHP 7.2.13 - my dynamic title script works there and on my WampServer with PHH 5.6 but not when I switch to PHP 7.1.26, 7.2.14, or 7.3.1

I have tried all the various solutions recommended when I searched for PHP Warning:  imagettftext(): Could not find/open font but none seem to resolve the problem

Anyone know how I can use Free Type Version 2.7 for the other versions of PHP?

 

Link to comment
Share on other sites

This appears to be a bug that was introduced in PHP 7.1.?

Does anyone know how I should code the suggested workaround referenced in https://github.com/e107inc/e107/issues/2956#issuecomment-355813801 to call realpath()

Debugging PHP script errors that do not return sufficient information is such a pain, I tried to use

echo "Rootpath is $rootpath <br />";
echo "Font1 is $font1 <br />";

but they never show on the screen,  I then tried to use

print ("Rootpath = $rootpath, Font1 = $font1, Font2 = $font2");
exit;

which did not work either

Link to comment
Share on other sites

6 minutes ago, Ken Roy said:

Debugging PHP script errors that do not return sufficient information is such a pain, I tried to use


echo "Rootpath is $rootpath <br />";
echo "Font1 is $font1 <br />";

but they never show on the screen,  I then tried to use


print ("Rootpath = $rootpath, Font1 = $font1, Font2 = $font2");
exit;

which did not work either

I usually write it like

echo "Rootpath is " . $rootpath . "<br />";

And even if they don't appear on the screen, look in the page source code as they sometimes show up there while not being in the HTML output.

Roger

Link to comment
Share on other sites

Thanks Roger,

my script is similar to your Google maps script that changes the pins except that it generates an image for the page heading from text variables.  I tried using your $rootpath approach but that does not work.  I suspect the problem is cause my Microsoft wanting their TTF fonts available for their IIS server, where they requested or caused a changed to PHP on Windows platforms to search their font locations and over course my font is not there, but I do not know enough to prove it.

Link to comment
Share on other sites

In case anyone else encounters a similar problem, I finally resolved this issue when I got a different error message after testing a change.

Quote

PHP Warning: imagettftext(): Invalid font filename

Solution was to change my

$font1 = 'font/Vagabond_Bold.ttf';
$font2 = 'font/Vagabond_Bold.ttf';

to use

$font1 = dirname(__FILE__) . "/font/Vagabond_Bold.ttf";
$font2 = dirname(__FILE__) . "/font/Vagabond_Bold.ttf";

as recommended in https://stackoverflow.com/questions/11008066/php-imagettftext-invalid-font-filename

Link to comment
Share on other sites

  • 2 years later...
On 4/12/2019 at 7:54 PM, Ken Roy said:

In case anyone else encounters a similar problem, I finally resolved this issue when I got a different error message after testing a change.

Solution was to change my


$font1 = 'font/Vagabond_Bold.ttf';
$font2 = 'font/Vagabond_Bold.ttf';

to use


$font1 = dirname(__FILE__) . "/font/Vagabond_Bold.ttf";
$font2 = dirname(__FILE__) . "/font/Vagabond_Bold.ttf";

as recommended in https://stackoverflow.com/questions/11008066/php-imagettftext-invalid-font-filename

I joined this forum to thank you. I also went to StackOverflow to upvote the answer. :) You saved me hours of searching.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...