/    Sign up×
Community /Pin to ProfileBookmark

font not found

I keep getting a “font not found” error whenever I try to use the imagettftext() function with the PHP4 installation on my own computer (running Apache 1.3 on Windows NT4). I have tried putting the fonts into all of the different folders I can think of to try to link from and even have the script using the following code to retrieve the fonts from a specified location but I still get the not found error. Does anyone have any ideas?

[code=php]
$dir = opendir(‘./’);
while (false !== ($file = readdir($dir))) {
if (eregi(‘ttf{1}$’, $file)){
$fonts[] = ‘./’.$file;
}
}
closedir($dir);
$font = realpath($fonts[0]);
imagettftext($image, 44, 15, 50, 200, $blue, $font, “Hello World”);
[/code]

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@SpectreReturnsDec 23.2005 — As far as my experience goes, the font must be in the same directory and when specifying it, you would just give the filename.
Copy linkTweet thisAlerts:
@bokehDec 25.2005 — Stephen, I don't quite know what is going wrong but I would try something along these lines maybe.[code=php]$current_dir = $_SERVER['DOCUMENT_ROOT'].str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);
$pointer = opendir($current_dir);
while (false !== ($file = readdir($pointer))) {
if (eregi('ttf{1}$', $file)){
$fonts[] = $current_dir.$file;
}
}
closedir($pointer);
$font = $fonts[0];
imagettftext($image, 44, 15, 50, 200, $blue, $font, "Hello World");[/code]
Copy linkTweet thisAlerts:
@felgallauthorDec 25.2005 — Thanks for the suggestion. Unfortunately it still doesn't work. I wonder where the code is looking for the fonts since it can't seem to find them from anywhere that I put them no matter how I try to specify their location. Guess I'll just have to give up trying to get it to work on my own computer for the time being.
Copy linkTweet thisAlerts:
@bokehDec 25.2005 — Don't give up so easily! On a windows machine the following works for me.[code=php]<?php
$font_dir = 'c:/windows/fonts/';
$pointer = opendir($font_dir);
while (false !== ($file = readdir($pointer))) {
if (eregi('(.ttf){1}$', $file)){
$fonts[] = $font_dir.$file;
}
}
closedir($pointer);
$font = $fonts[20]; // make sure this isn't a symbol font

header ("Content-type: image/png");
$image = imagecreatefromstring(file_get_contents('1.jpg')); // get a real image to work on
$blue = imagecolorallocate($image, 0, 0, 255);
imagettftext($image, 12, 0, 20, 20, $blue, $font, "Hello World");
imagepng($image);
imagedestroy($image);
?>[/code]
Copy linkTweet thisAlerts:
@bokehJan 30.2006 — Stephen, did you ever solve this?

If not here is something else to try:[code=php]<?php
$dir = opendir('./');
while (false !== ($file = readdir($dir))) {
if (eregi('ttf{1}$', $file)){
$fonts[] = './'.$file;
}
}
closedir($dir);
putenv('GDFONTPATH=' . realpath('.'));
imagettftext($image, 44, 15, 50, 200, $blue, $font[0], "Hello World");
?>[/code]
×

Success!

Help @felgall spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...