Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 29 Sep 2002 22:02:42 +0200
From:      Eivind Olsen <eivind@aminor.no>
To:        freebsd-questions@FreeBSD.ORG
Cc:        la3sg@sensewave.com
Subject:   Re: PHP, GD2 and True Type Fonts
Message-ID:  <31773017.1033336962@[192.168.0.2]>
In-Reply-To: <3D934202.6025.1DCC81E@localhost>
References:   <3D934202.6025.1DCC81E@localhost>

next in thread | previous in thread | raw e-mail | index | archive | help
--On 26. september 2002 17:21 +0100 Kjell <junkmail@sensewave.com> wrote:
> I am  calling the GD2 package from PHP to generate graphics to be
> displayed  on web pages. Everything I have tried are working fine, with
> one exception:  When I make a call like
> $size = ImageTTFBbox (10, 0, "fonts/arial.ttf" , "hello");
> I get an arror message like
> Warning: Could not find/open font in /home/www/htdocs/t3.php on line 21
> Is it required to compile GD2 with certain options to be able to use True
> Type  Fonts?
> Could it be something wrong with my font files?

I seem to recall that the fonts should reside in 
"/usr/share/fonts/truetype/" and should be referred to as just the name of 
the font-file without the ".ttf" on the end.

Here is an example. I have several *.ttf files in /usr/share/fonts/truetype 
(which is just a symlink to /usr/X11R6/lib/X11/fonts/webfonts which was 
populated by installing the x11-fonts/webfonts port):

eivind@trisha:~ > ls -la /usr/share/fonts/truetype/ | grep courbi
-r--r--r--   1 root  wheel  234788 Sep 29 20:16 courbi.ttf
eivind@trisha:~ >

Here is an example script (taken from the "Programming PHP" O'Reilly-book):

eivind@trisha:~ > cat ~/public_html/fonttest.php
<?php

$im = ImageCreate(350, 70);
$white = ImageColorAllocate($im, 0xFF,0xFF,0xFF);
$black = ImageColorAllocate($im, 0x00,0x00,0x00);
ImageTTFText($im, 20, 0, 10, 40, $black, 'courbi', 'The Courier TTF font');
header('Content-Type: image/png');
ImagePNG($im);
?>

eivind@trisha:~ >

As you can see it references the font as "courbi" even though the fontfile 
is "courbi.ttf".

Someone mentioned absolute paths, but absolute paths are only required if 
you're using GD1 (and you said you were using GD2) or if your fonts are not 
found in /usr/share/fonts/truetype/

I hope this helped.

-- 
Eivind Olsen
eivind@aminor.no


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?31773017.1033336962>