Jump to content
TNG Community
Sign in to follow this  
Ken Roy

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

Recommended Posts

Ken Roy

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?

 

Share this post


Link to post
Share on other sites
Ken Roy

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

Share this post


Link to post
Share on other sites
theKiwi
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

Share this post


Link to post
Share on other sites
Ken Roy

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.

Share this post


Link to post
Share on other sites
Ken Roy

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

Share this post


Link to post
Share on other sites
eaweb
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×