imagettftext() path to font

Discussion in 'PHP' started by shuguesebookers, Mar 10, 2009.

  1. #1
    Hello,

    I've discovered this marvelous method imagettftext()
    PHP: imagettftext - Manual
    who allows a preview of a TTF font.

    One problem : it only works when the font is in the same folder than the script.
    "arial.ttf", when "http://www.mysite.com/data/arial.ttf", it doesn't work.
    I must put my font in an other folder.

    Thanks for helping me, Sylvain.
     
    shuguesebookers, Mar 10, 2009 IP
  2. shubhamjain1

    shubhamjain1 Peon

    Messages:
    75
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    shubhamjain1, Mar 10, 2009 IP
  3. shuguesebookers

    shuguesebookers Guest

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yea this Is what I told : I tried "http://www.mysite.com/data/arial.ttf"
    but doesn t work, althought the file exist... very strange.

    Is that what you meant ?
     
    shuguesebookers, Mar 10, 2009 IP
  4. buldozerceto

    buldozerceto Active Member

    Messages:
    1,137
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    88
    #4
    you need absolute path:
    <?php
    define('ABSPATH','/directory/where/ttf/is');
    // Set the enviroment variable for GD
    putenv('GDFONTPATH=' . ABSPATH);

    // Name the font to be used (note the lack of the .ttf extension)
    $font = 'arial';
    ?>
     
    buldozerceto, Mar 10, 2009 IP