Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Aug 2007
    Location
    maine,usa
    Posts
    151
    Thanks
    2
    Thanked 1 Time in 1 Post

    GD help with Error

    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?

    PHP Code:
    <?php 
    $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($image255255255); 
    $font "fonts/hyo.ttf"
    $fontSize "18";
    $ret imagettfbbox($fontSize0$font$town);
    imagettftext($image$fontSize0, ($imageWidth $ret[2]) / 212$color$font$month);

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

    // Output & Free Memory
    header("Content-type: image/png");
    imagepng($image); 
    imagedestroy($image); 
    ?>

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,066
    Thanks
    2
    Thanked 319 Times in 311 Posts
    What version of GD library?

    The php manual contains the following which mentions the error you are getting -
    fontfile
    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.
    PHP Code:
    <?php
    // Set the enviroment variable for GD
    putenv('GDFONTPATH=' realpath('.'));
           
    The y-ordinateThis sets the position of the fonts baselinenot
           the very bottom of the character
    .
    // Name the font to be used (note the lack of the .ttf extension)
    $font 'SomeFont';
    ?>
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    Regular Coder
    Join Date
    Aug 2007
    Location
    maine,usa
    Posts
    151
    Thanks
    2
    Thanked 1 Time in 1 Post
    I just noticed the filename was wrong, now my text isn't showing up tho.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •