www.webdeveloper.com
Results 1 to 5 of 5

Thread: Simple GD Library Question

  1. #1
    Join Date
    Dec 2005
    Posts
    2,984

    Simple GD Library Question

    I hate it when I just can't see the problem in such a simple script.

    This doesn't output the value of $_GET['n'] onto my image:
    PHP Code:
        $numberFont "trebuchet_bold.ttf";
        
    header('Content-type: image/png');
        
    $marker imagecreatefrompng('markerImage.png'); //create the working image resource from the invitation
        
        
    imagealphablending($markerfalse);
        
    imagesavealpha($markertrue);
        
            
    //get the color resources of the font
            
    $whiteColor imagecolorallocate($marker,255,255,255);        

            
    imagettftext($marker,10,0,0,0,$whiteColor,$numberFont,$_GET['n']);
            
            
    imagepng($marker); 
    For anybody who is enough of a saint to look at this for me, just run this script in a directory with the two attached files. It's just a simple png and the trebuchet bold font file.
    Attached Files Attached Files
    I've switched careers...
    I'm NO LONGER a scientist,
    but now a web developer...
    awesome.

  2. #2
    Join Date
    Oct 2007
    Posts
    370
    untested, but i'd try this:

    Quote Originally Posted by php.net
    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('.'));

    // Name the font to be used (note the lack of the .ttf extension)
    $font 'SomeFont';
    ?>

  3. #3
    Join Date
    Oct 2008
    Location
    Seattle, Wa
    Posts
    695
    You try passing it in as a var instead of a global?

    PHP Code:
    $n$_GET['n'];
    imagettftext($marker,10,0,0,0,$whiteColor,$numberFont,$n); 

    Seems pretty silly but I noticed in the Docs no one is using super globals
    to pass in data, AKA
    PHP Code:
    imagettftext($im2001121$grey$font$text); 
    What does $_GET['n']; print to?
    _,-O
    O
    (_)) ubuntu -
    -`-O

  4. #4
    Join Date
    Dec 2005
    Posts
    2,984
    Don't know what the problem was with this script, but I solved it by just copying and pasting from an old GD script that worked like this and trimmed it down to my needs. Still don't understand what the problem was with it....could've been something simple - but printing $_GET['n'] always printed out the number to the screen when I turned the png headers off (it was usually something like script.php?n=374)
    I've switched careers...
    I'm NO LONGER a scientist,
    but now a web developer...
    awesome.

  5. #5
    Join Date
    Oct 2008
    Location
    Seattle, Wa
    Posts
    695
    Very weird business?
    _,-O
    O
    (_)) ubuntu -
    -`-O

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles