Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
645 views
in Technique[技术] by (71.8m points)

php - Invalid font filename (imagettfbox)

This question has been asked over and over but I could not find the correct answer to my problem... As a little background note, all the code was working perfectly before we moved the class file from /application/lib/class to /library/class ...

I have tried to play with GDFONTPATH, relative, absolute paths with and without the file extension to no avail. Here is some of the lines we have tried so far:

putenv('GDFONTPATH=' . realpath(dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'fonts'));
/*1*/  $FontName = dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'fonts'.DIRECTORY_SEPARATOR.basename($FontName,'.ttf');
/*2*/  $FontName = 'pChartfonts\'.basename($FontName);
/*3*/  $FontName =basename($FontName);
$coords = imagettfbbox($FontSize, 0, $FontName, $Text);

Multiple combination of those tries have also been used to no avail. I am really annoyed by this problem as the #1, when echo'ed gives a full path that opens up the correct font file if copy/pasted in win explorer.

It might help to know the absolute path of the file getting the error and the path of the fontname...

C:wampwwwapplication_bundleLibrarypChartclasspImage.class.php
C:wampwwwapplication_bundleLibrarypChartfontsarialuni.ttf

We are experiencing this problem on all dev platforms (Win, Mac and Linux) PHP 5.3.13

Thank you for your assistance.

Edit: It seems as if the file is not found / the server is not looking at the right folder... If someone could help troubleshoot the problem by pointing out how to figure out what path GD is trying to open would really help.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

We have figured out how to make it work.

To put it short, we were including the class file and then calling the methods to write the text. We were doing something like this:

$classPath = 'pChart/';
include($classPath.'/class/pImage.class.php');
//... inside the pImage.class we passed font like this: $FontName = $classPath.'/fonts/arialuni.ttf';
imagettfbbox($FontSize, 0, $FontName, $Text)

It did not work whatever we did before or after... Until we changed the $classPath to

$classpath = '../library/pChart/';

Note that they are (or should) point exactly to the same folder as the code is executed from a file in library root.

We have tried to find why absolute paths were not working but could not reproduce the bug in an isolated environment so there's something fishy with our architecture.

Thank you for your time everyone.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...