True Type Fonts (FreeType) - GD - PHP 4.3.2

This is a discussion on True Type Fonts (FreeType) - GD - PHP 4.3.2 within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hello, I'm having a problem using the TTF support in GD. I just installed the latest release of PHP (...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-04-2003
Zac Hester
 
Posts: n/a
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


Reply With Quote
  #2 (permalink)  
Old 07-07-2003
Zac Hester
 
Posts: n/a
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. :)



Reply With Quote
  #3 (permalink)  
Old 07-08-2003
David Robley
 
Posts: n/a
Default Re: True Type Fonts (FreeType) - GD - PHP 4.3.2

In article <3f09b371$1@news.enetis.net>, news@planetzac.net says...
> "David Robley" <robleyd@ozemail.com.oz> wrote in message
> news:MPG.19729b96887b724f9896b7@news.spiderweb.com .au...
> > In article <3f04dfe3$1@news.enetis.net>, news@planetzac.net 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;

Reply With Quote
  #4 (permalink)  
Old 07-08-2003
Zac Hester
 
Posts: n/a
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>, news@planetzac.net says...
> > "David Robley" <robleyd@ozemail.com.oz> wrote in message
> > news:MPG.19729b96887b724f9896b7@news.spiderweb.com .au...
> > > In article <3f04dfe3$1@news.enetis.net>, news@planetzac.net 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


Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 02:55 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0