True Type Fonts (FreeType) - GD - PHP 4.3.2

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default True Type Fonts (FreeType) - GD - PHP 4.3.2

    Hello,

    I'm having a problem using the TTF support in GD. I just installed the
    latest release of PHP (4.3.2) and the latest version of FreeType (1.3.1).
    Everything compiled fine and a call to phpinfo() says it's all installed
    exactly as it should be:

    GD Support enabled
    GD Version bundled (2.0.12 compatible)
    FreeType Support enabled
    FreeType Linkage with TTF library
    GIF Read Support enabled
    JPG Support enabled
    PNG Support enabled
    WBMP Support enabled
    XBM Support enabled

    I copied a few fonts off of my Windows machine to my web site. Now, I use
    the universal demonstration script found on every site showing how to use
    TTF support:

    <?php
    header("Content-type: image/jpeg");
    $im = imagecreate(400,30);
    $white = imagecolorallocate($im, 255,255,255);
    $black = imagecolorallocate($im, 0,0,0);
    imagettftext($im, 20, 0, 10, 20, $black,
    "/usr/loca/apache/htdocs/systems/fonts/arial.ttf",
    "Testing... Omega: &amp;#937;");
    imagejpeg($im);
    imagedestroy($im);
    ?>

    Running this script only displays a blank, white image 400x30 pixels.
    There's no text. I turned off the "Content-Type" header to see if there's
    any errors or warnings being generated and it just spits out the image data
    like it should. (I have all the default error reporting settings turned
    on.)

    My next test was to use the imagestring() function in place of the
    imagettftext() function. Using that function, the text displays exactly as
    expected.

    I also used PHP's file_exists() function to make sure I had the path correct
    on the font file and it returned a "1"

    Just for giggles, I ran a print_r() on the return of imagettftext() (without
    the "Content-Type" header) and it reported the following values for the
    bounding box:

    Array (
    [0] => 136397764
    [1] => -1077944084
    [2] => 136398444
    [3] => 136894220
    [4] => 5
    [5] => 136785624
    [6] => 136890096
    [7] => 136894828
    )

    This looks like there's something way messed up with how FreeType is reading
    the font file. So, I figure I'm missing something with installing fonts on
    my web server. I look around and find a utility for installing font
    information for X called ttmkfdir. It just compiles a list of font names so
    a font rendering application can use the font files. I installed the
    utility and ran it on my font directory. (It ran as expected.) Results:
    still nothing. I even tried copying the fonts to the accepted fonts
    directory (/usr/share/fonts/truetype) and ran the ttmkfdir program once
    again. I changed the path to the font, and still no dice. The bad thing
    about this function is that it doesn't error out when the font file is
    invalid. (I tried that, too.)

    So now, I'm here pleading for anyone's help. If you've ran into this
    scenario and fixed it, I'd appreciate any help. If you just have a good
    idea as to what I'm missing, I'd also love to hear from you. If it matters,
    I'm running Apache 1.3.27 on FreeBSD 4.7.

    Thanks, in advnace, for any help anyone can offer.

    -Zac


    Zac Hester Guest

  2. Similar Questions and Discussions

    1. Linux, True Type Fonts and Flash Player
      I also have problems about fonts... but not those, which you have. I may help you about fonts. The 'installed fonts' may be two: those in the...
    2. True Type and Type1 font issue
      in my environment we run windows xp and acrobat 5/6 (a mix) we have the need for both the true type and type1 versions of the Minion font. we...
    3. How to Combine True Type Font with my project
      Dear All I've made a dictionary project with director. I've used two true type fonts in my project I wanted to place two true type fonts in...
    4. True type fonts in Windows 2000
      I created a CD-ROM in french. I have problems with accents (èàê) that don't appear properly. I cannot replace my text with bitmap because the...
    5. #25734 [NEW]: string false type-casts into boolean TRUE
      From: rbotzer at yahoo dot com Operating system: MacOS X PHP version: 4.3.3 PHP Bug Type: Feature/Change Request Bug...
  3. #2

    Default True Type Fonts (FreeType) - GD - PHP 4.3.2

    Hello,

    I'm having a problem using the TTF support in GD. I just installed the
    latest release of PHP (4.3.2) and the latest version of FreeType (1.3.1).
    Everything compiled fine and a call to phpinfo() says it's all installed
    exactly as it should be:

    GD Support enabled
    GD Version bundled (2.0.12 compatible)
    FreeType Support enabled
    FreeType Linkage with TTF library
    GIF Read Support enabled
    JPG Support enabled
    PNG Support enabled
    WBMP Support enabled
    XBM Support enabled

    I copied a few fonts off of my Windows machine to my web site. Now, I use
    the universal demonstration script found on every site showing how to use
    TTF support:

    <?php
    header("Content-type: image/jpeg");
    $im = imagecreate(400,30);
    $white = imagecolorallocate($im, 255,255,255);
    $black = imagecolorallocate($im, 0,0,0);
    imagettftext($im, 20, 0, 10, 20, $black,
    "/usr/loca/apache/htdocs/systems/fonts/arial.ttf",
    "Testing... Omega: &amp;#937;");
    imagejpeg($im);
    imagedestroy($im);
    ?>

    Running this script only displays a blank, white image 400x30 pixels.
    There's no text. I turned off the "Content-Type" header to see if there's
    any errors or warnings being generated and it just spits out the image data
    like it should. (I have all the default error reporting settings turned
    on.)

    My next test was to use the imagestring() function in place of the
    imagettftext() function. Using that function, the text displays exactly as
    expected.

    I also used PHP's file_exists() function to make sure I had the path correct
    on the font file and it returned a "1"

    Just for giggles, I ran a print_r() on the return of imagettftext() (without
    the "Content-Type" header) and it reported the following values for the
    bounding box:

    Array (
    [0] => 136397764
    [1] => -1077944084
    [2] => 136398444
    [3] => 136894220
    [4] => 5
    [5] => 136785624
    [6] => 136890096
    [7] => 136894828
    )

    This looks like there's something way messed up with how FreeType is reading
    the font file. So, I figure I'm missing something with installing fonts on
    my web server. I look around and find a utility for installing font
    information for X called ttmkfdir. It just compiles a list of font names so
    a font rendering application can use the font files. I installed the
    utility and ran it on my font directory. (It ran as expected.) Results:
    still nothing. I even tried copying the fonts to the accepted fonts
    directory (/usr/share/fonts/truetype) and ran the ttmkfdir program once
    again. I changed the path to the font, and still no dice. The bad thing
    about this function is that it doesn't error out when the font file is
    invalid. (I tried that, too.)

    So now, I'm here pleading for anyone's help. If you've ran into this
    scenario and fixed it, I'd appreciate any help. If you just have a good
    idea as to what I'm missing, I'd also love to hear from you. If it matters,
    I'm running Apache 1.3.27 on FreeBSD 4.7.

    Thanks, in advnace, for any help anyone can offer.

    -Zac


    Zac Hester Guest

  4. #3

    Default Re: True Type Fonts (FreeType) - GD - PHP 4.3.2

    Paul,

    Thanks for the idea. I tried what you said and used the
    imagecreatetruecolor() function and it does the exact same thing. It
    creates a blank, white picture.

    Thank you for your time,
    Zac


    "Paul Liversidge" <paul_liversidge@hotmail.com> wrote in message
    news:bf26a194.0307032149.379bccf6@posting.google.c om...
    > "Zac Hester" <news@planetzac.net> wrote in message
    news:<3f04dfe3$1@news.enetis.net>...
    > > Hello,
    > >
    > > I'm having a problem using the TTF support in GD. I just installed the
    > > latest release of PHP (4.3.2) and the latest version of FreeType
    (1.3.1).
    > > Everything compiled fine and a call to phpinfo() says it's all installed
    > > exactly as it should be:
    > >
    > > GD Support enabled
    > > GD Version bundled (2.0.12 compatible)
    > > FreeType Support enabled
    > > FreeType Linkage with TTF library
    > > GIF Read Support enabled
    > > JPG Support enabled
    > > PNG Support enabled
    > > WBMP Support enabled
    > > XBM Support enabled
    > >
    > > I copied a few fonts off of my Windows machine to my web site. Now, I
    use
    > > the universal demonstration script found on every site showing how to
    use
    > > TTF support:
    > >
    > > <?php
    > > header("Content-type: image/jpeg");
    > > $im = imagecreate(400,30);
    > > $white = imagecolorallocate($im, 255,255,255);
    > > $black = imagecolorallocate($im, 0,0,0);
    > > imagettftext($im, 20, 0, 10, 20, $black,
    > > "/usr/loca/apache/htdocs/systems/fonts/arial.ttf",
    > > "Testing... Omega: &amp;#937;");
    > > imagejpeg($im);
    > > imagedestroy($im);
    > > ?>
    >
    > I actually think it's a problem with the GD but I'm only guessing
    > having had similar problems with color allocation.
    >
    > As you've got GD v2 I'd replace the imagecreate with
    > imagecreatetruecolor
    >
    > If that doesn't work, keep the imagecreatetruecolor, GD v2's preferred
    > way of creating images and add this line before the imagettftext.
    >
    > imagefilledrectangle ($im, 0, 0, 399, 29, $white);
    >
    > imagecreate used to set the background to the first allocated colour,
    > white in this example and it seems to work correctly given your
    > results. However, in a recent application this didn't work and I had
    > to paint the background. This little addition is grasping at straws
    > but I think the first one may solve it. :)

    Zac Hester Guest

  5. #4

    Default Re: True Type Fonts (FreeType) - GD - PHP 4.3.2

    Paul,

    Thanks for the idea. I tried what you said and used the
    imagecreatetruecolor() function and it does the exact same thing. It
    creates a blank, white picture.

    Thank you for your time,
    Zac


    "Paul Liversidge" <paul_liversidge@hotmail.com> wrote in message
    news:bf26a194.0307032149.379bccf6@posting.google.c om...
    > "Zac Hester" <news@planetzac.net> wrote in message
    news:<3f04dfe3$1@news.enetis.net>...
    > > Hello,
    > >
    > > I'm having a problem using the TTF support in GD. I just installed the
    > > latest release of PHP (4.3.2) and the latest version of FreeType
    (1.3.1).
    > > Everything compiled fine and a call to phpinfo() says it's all installed
    > > exactly as it should be:
    > >
    > > GD Support enabled
    > > GD Version bundled (2.0.12 compatible)
    > > FreeType Support enabled
    > > FreeType Linkage with TTF library
    > > GIF Read Support enabled
    > > JPG Support enabled
    > > PNG Support enabled
    > > WBMP Support enabled
    > > XBM Support enabled
    > >
    > > I copied a few fonts off of my Windows machine to my web site. Now, I
    use
    > > the universal demonstration script found on every site showing how to
    use
    > > TTF support:
    > >
    > > <?php
    > > header("Content-type: image/jpeg");
    > > $im = imagecreate(400,30);
    > > $white = imagecolorallocate($im, 255,255,255);
    > > $black = imagecolorallocate($im, 0,0,0);
    > > imagettftext($im, 20, 0, 10, 20, $black,
    > > "/usr/loca/apache/htdocs/systems/fonts/arial.ttf",
    > > "Testing... Omega: &amp;#937;");
    > > imagejpeg($im);
    > > imagedestroy($im);
    > > ?>
    >
    > I actually think it's a problem with the GD but I'm only guessing
    > having had similar problems with color allocation.
    >
    > As you've got GD v2 I'd replace the imagecreate with
    > imagecreatetruecolor
    >
    > If that doesn't work, keep the imagecreatetruecolor, GD v2's preferred
    > way of creating images and add this line before the imagettftext.
    >
    > imagefilledrectangle ($im, 0, 0, 399, 29, $white);
    >
    > imagecreate used to set the background to the first allocated colour,
    > white in this example and it seems to work correctly given your
    > results. However, in a recent application this didn't work and I had
    > to paint the background. This little addition is grasping at straws
    > but I think the first one may solve it. :)

    Zac Hester Guest

  6. #5

    Default Re: True Type Fonts (FreeType) - GD - PHP 4.3.2

    In article <3f09b371$1@news.enetis.net>, [email]news@planetzac.net[/email] says...
    > "David Robley" <robleyd@ozemail.com.oz> wrote in message
    > news:MPG.19729b96887b724f9896b7@news.spiderweb.com .au...
    > > In article <3f04dfe3$1@news.enetis.net>, [email]news@planetzac.net[/email] says...
    > > >
    > > > <?php
    > > > header("Content-type: image/jpeg");
    > > > $im = imagecreate(400,30);
    > > > $white = imagecolorallocate($im, 255,255,255);
    > > > $black = imagecolorallocate($im, 0,0,0);
    > > > imagettftext($im, 20, 0, 10, 20, $black,
    > > > "/usr/loca/apache/htdocs/systems/fonts/arial.ttf",
    > >
    > > Is this a copy/paste? If so, the path looks wrong.
    > >
    > > <SNIP rest>
    >
    > Nope, that's the path to my fonts directory for my site. Just to make sure
    > I wasn't insane, I put a file_exists() check in the code to make sure I
    > typed the path and filename to the font file correctly. Everything is where
    > it should be.
    >
    > Thank you for your time,
    > Zac
    OK, but it does say /usr/loca/... where normally it would be
    /usr/local/....


    --
    Quod subigo farinam

    $email =~ s/oz$/au/o;

    David Robley Guest

  7. #6

    Default Re: True Type Fonts (FreeType) - GD - PHP 4.3.2

    In article <3f09b371$1@news.enetis.net>, [email]news@planetzac.net[/email] says...
    > "David Robley" <robleyd@ozemail.com.oz> wrote in message
    > news:MPG.19729b96887b724f9896b7@news.spiderweb.com .au...
    > > In article <3f04dfe3$1@news.enetis.net>, [email]news@planetzac.net[/email] says...
    > > >
    > > > <?php
    > > > header("Content-type: image/jpeg");
    > > > $im = imagecreate(400,30);
    > > > $white = imagecolorallocate($im, 255,255,255);
    > > > $black = imagecolorallocate($im, 0,0,0);
    > > > imagettftext($im, 20, 0, 10, 20, $black,
    > > > "/usr/loca/apache/htdocs/systems/fonts/arial.ttf",
    > >
    > > Is this a copy/paste? If so, the path looks wrong.
    > >
    > > <SNIP rest>
    >
    > Nope, that's the path to my fonts directory for my site. Just to make sure
    > I wasn't insane, I put a file_exists() check in the code to make sure I
    > typed the path and filename to the font file correctly. Everything is where
    > it should be.
    >
    > Thank you for your time,
    > Zac
    OK, but it does say /usr/loca/... where normally it would be
    /usr/local/....


    --
    Quod subigo farinam

    $email =~ s/oz$/au/o;

    David Robley Guest

  8. #7

    Default Re: True Type Fonts (FreeType) - GD - PHP 4.3.2

    "David Robley" <robleyd@ozemail.com.oz> wrote in message
    news:MPG.1975313961663d9896ba@news.spiderweb.com.a u...
    > In article <3f09b371$1@news.enetis.net>, [email]news@planetzac.net[/email] says...
    > > "David Robley" <robleyd@ozemail.com.oz> wrote in message
    > > news:MPG.19729b96887b724f9896b7@news.spiderweb.com .au...
    > > > In article <3f04dfe3$1@news.enetis.net>, [email]news@planetzac.net[/email] says...
    > > > >
    > > > > <?php
    > > > > header("Content-type: image/jpeg");
    > > > > $im = imagecreate(400,30);
    > > > > $white = imagecolorallocate($im, 255,255,255);
    > > > > $black = imagecolorallocate($im, 0,0,0);
    > > > > imagettftext($im, 20, 0, 10, 20, $black,
    > > > > "/usr/loca/apache/htdocs/systems/fonts/arial.ttf",
    > > >
    > > > Is this a copy/paste? If so, the path looks wrong.
    > > >
    > > > <SNIP rest>
    > >
    > > Nope, that's the path to my fonts directory for my site. Just to make
    sure
    > > I wasn't insane, I put a file_exists() check in the code to make sure I
    > > typed the path and filename to the font file correctly. Everything is
    where
    > > it should be.
    > >
    > > Thank you for your time,
    > > Zac
    >
    > OK, but it does say /usr/loca/... where normally it would be
    > /usr/local/....
    >
    >
    > --
    > Quod subigo farinam
    >
    > $email =~ s/oz$/au/o;
    >
    Yup, that was my mistake. The path wasn't copy/pasted from my code. The
    important thing is that the path is correct in my code.

    Thanks for the reply,
    Zac


    Zac Hester Guest

  9. #8

    Default Re: True Type Fonts (FreeType) - GD - PHP 4.3.2

    "David Robley" <robleyd@ozemail.com.oz> wrote in message
    news:MPG.1975313961663d9896ba@news.spiderweb.com.a u...
    > In article <3f09b371$1@news.enetis.net>, [email]news@planetzac.net[/email] says...
    > > "David Robley" <robleyd@ozemail.com.oz> wrote in message
    > > news:MPG.19729b96887b724f9896b7@news.spiderweb.com .au...
    > > > In article <3f04dfe3$1@news.enetis.net>, [email]news@planetzac.net[/email] says...
    > > > >
    > > > > <?php
    > > > > header("Content-type: image/jpeg");
    > > > > $im = imagecreate(400,30);
    > > > > $white = imagecolorallocate($im, 255,255,255);
    > > > > $black = imagecolorallocate($im, 0,0,0);
    > > > > imagettftext($im, 20, 0, 10, 20, $black,
    > > > > "/usr/loca/apache/htdocs/systems/fonts/arial.ttf",
    > > >
    > > > Is this a copy/paste? If so, the path looks wrong.
    > > >
    > > > <SNIP rest>
    > >
    > > Nope, that's the path to my fonts directory for my site. Just to make
    sure
    > > I wasn't insane, I put a file_exists() check in the code to make sure I
    > > typed the path and filename to the font file correctly. Everything is
    where
    > > it should be.
    > >
    > > Thank you for your time,
    > > Zac
    >
    > OK, but it does say /usr/loca/... where normally it would be
    > /usr/local/....
    >
    >
    > --
    > Quod subigo farinam
    >
    > $email =~ s/oz$/au/o;
    >
    Yup, that was my mistake. The path wasn't copy/pasted from my code. The
    important thing is that the path is correct in my code.

    Thanks for the reply,
    Zac


    Zac Hester Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139