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 2 of 2
  1. #1
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts

    Text on image with ImageCreate error

    I'm working on a php script that will put text onto images. I get the following error but I have the .ttf font file in the same folder as the script. Line 11 is the last line in the code I posted. Any ideas why I get the error?


    Warning: imagettftext(): Could not find/open font in /home/httpd/vhosts/stubby.ca/httpdocs/test/index.php on line 11

    PHP Code:
    <?php
    $image 
    ImageCreateFromGIF("test.gif");
    $color imagecolorallocate($image0xFF0xFF0xFF);
    $colorShadow imagecolorallocate($image0x660x660x66);
    $font 'LAPLDB.TTF';
    $fontSize "10";
    $fontRotation "0";
    $str "Copyright 2007");

    /* Shadow */
    ImageTTFText($image$fontSize$fontRotation722$colorShadow$font$str);
    Leonard Whistler

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Location
    Canada, eh?
    Posts
    133
    Thanks
    2
    Thanked 3 Times in 3 Posts
    PHP will look in the font folder of the local machine for the font, not the current directory where the file is. You need to directly specify where the font is. Something like this:

    PHP Code:
    $font $_SERVER['DOCUMENT_ROOT']."/test/LAPLDB.TTF"
    Make sure the case is proper and everything.
    Bored? Might as well play Fantasian Kingdoms: http://www.fantasiankingdoms.com/

    Check out my JavaScript Image Project: http://codingforums.com/showthread.php?t=185231


  •  

    Posting Permissions

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