View Full Version : GD help with Error

09-05-2007, 03:41 AM
Ok I have this script for making a weather Icon. Right now i'm trying to figure out the error message:
Warning: imagettfbbox() [function.imagettfbbox]: Could not find/open font in /var/www/includes/wx.php on line 13

Warning: imagettftext() [function.imagettftext]: Could not find/open font in /var/www/includes/wx.php on line 14

Warning: Cannot modify header information - headers already sent by (output started at /var/www/includes/wx.php:8) in /var/www/includes/wx.php on line 24

I'm not concerned with the second image at the moment eventualy it will get placed in the upper right hand corner of the base image. any Ideas on this?

$town = 'BoothabyHarbor';
$temp = '90';
// Generate Image & set width
$image = imagecreatefrompng("../images/weather/wBack.png");
$image2 = imagecreatefrompng("../images/weather/wx/40.png");
$imageWidth = '230';
echo $imageWidth;
// Generate Town
$color = imagecolorallocate($image, 255, 255, 255);
$font = "fonts/hyo.ttf";
$fontSize = "18";
$ret = imagettfbbox($fontSize, 0, $font, $town);
imagettftext($image, $fontSize, 0, ($imageWidth - $ret[2]) / 2, 12, $color, $font, $month);

// Generate Temperature
$color = imagecolorallocate($image, 0, 0, 0);
$font = "fonts/arial.ttf";
$fontSize = "14";
$ret = imagettfbbox($fontSize, 0, $font, $temp);
imagettftext($image, $fontSize, 0, ($imageWidth - $ret[2]) / 2, 38, $color, $font, $day);

// Output & Free Memory
header("Content-type: image/png");

09-05-2007, 04:23 AM
What version of GD library?

The php manual contains the following which mentions the error you are getting -

The path to the TrueType font you wish to use.

Depending on which version of the GD library PHP is using, when fontfile does not begin with a leading / then .ttf will be appended to the filename and the library will attempt to search for that filename along a library-defined font path.

When using versions of the GD library lower than 2.0.18, a space character, rather than a semicolon, was used as the 'path separator' for different font files. Unintentional use of this feature will result in the warning message: Warning: Could not find/open font. For these affected versions, the only solution is moving the font to a path which does not contain spaces.

In many cases where a font resides in the same directory as the script using it the following trick will alleviate any include problems.

// Set the enviroment variable for GD
putenv('GDFONTPATH=' . realpath('.'));
The y-ordinate. This sets the position of the fonts baseline, not
the very bottom of the character.
// Name the font to be used (note the lack of the .ttf extension)
$font = 'SomeFont';

09-05-2007, 05:02 AM
I just noticed the filename was wrong, now my text isn't showing up tho.