note 33440 added to function.imagettftext
| From: | (chew-the-fat@web.de) | Date: | Thu, 26 Jun 2003 03:22:25 +0000 |
| Subject: | note 33440 added to function.imagettftext | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-51021@lists.php.net to get a copy of this message | ||
Here's the reason why you (sometimes) have
to use absolute filenames for the 'fontfile'-parameter:
The libgd extension for PHP searches for TTF
fonts in the following order:
- If an absolute path is given, GD opens that font.
- If the font cannot be found and the
environment variable GDFONTPATH is set,
GD looks for the font in these folders.
- If the font still cannot be found, GD searches
the font in DEFAULT_FONTPATH, which has been
set to C:\winnt\fonts (or something similar for
un*x platforms). Note that this path is
statically compiled into the extension!
This means that only users, who installed
Windows to c:\winnt, are able to load
fonts without using absolute filenames.
To solve this problem, set the GDFONTPATH
environment variable to your real windows font dir.
(Windows NT: Start->Settings->Control Panel->
System->Advanced->Environment Variables)
Now you can use short filenames, such as "times.ttf"
or even "times" and GD finds the correct font :)
Here's the responsible code from php/ext/gd/libgd/gd.h:
(Note: I had to wrap the line for unix because it was too long)
#ifndef WIN32
/* default fontpath for unix systems */
#define DEFAULT_FONTPATH
"/usr/X11R6/lib/X11/fonts/TrueType:
/usr/X11R6/lib/X11/fonts/truetype:
/usr/X11R6/lib/X11/fonts/TTF:
/usr/share/fonts/TrueType:
/usr/share/fonts/truetype:
/usr/openwin/lib/X11/fonts/TrueType:
/usr/X11R6/lib/X11/fonts/Type1:."
#define PATHSEPARATOR ":"
#else
/* default fontpath for windows systems */
#define DEFAULT_FONTPATH "c:\\winnt\\fonts;."
#define PATHSEPARATOR ";"
#endif
And here's an interesting note about the true meaning
of the space character (also taken from gd.h):
/*
* The character (space) used to separate alternate fonts in the
* fontlist parameter to gdImageStringFT.
*/
Actually, fontfile is a space-separated list of filenames.
GD tries to open the first file, if it fails, GD tries to
open the second file, and so on.
For example:
imagettftext($im, 20, 0, 10, 20, $black,
"tahoma.ttf arial.ttf", "texttexttext");
GD will try to open tahoma.ttf. If tahoma is not
available, GD will try to load arial.ttf.
Unfortunately there does not seem to be a way to
escape the space character, so you cannot use it in fontfile.
However, you can use as many spaces as
you wish in GDFONTPATH ;)
I hope this helped to clarify some things, as there
didn't seem to be any previous comment about this.
----
Manual Page -- http://www.php.net/manual/en/function.imagettftext.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33440
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33440&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33440&report=yes