Truetype fonts in php

(didn’t get a response on Programming, so I’m trying here)

I’m using a Truetype font to write text strings to .png files I’m creating on the fly with the PHP4 image functions.

Specifically, I’m using

  • imagettfbbox to get the string length (to determine image width)
  • imagettftext to write the string

I was only able to find one font (at least on yoda), Vera, which is prettyt fugly. I found it located at:


Are there other, more attractive fonts, elsewhere on the box that I’m just not finding?


  • can/should I install my own truetype fonts in my home directory? If so, how?
  • should I be looking at something other than truetype?

I’m pretty sure you can just upload fonts and then use the path to that font and it’ll work just fine.

For 30% more diskspace, 30% more bandwidth, and $40 off use promo code [color=#CC0000]THEFULLMONTY[/color]

Yes, you can use any True Type font. I made a Captcha module that renders the characters using fonts from a TTF I uploaded and referenced.

I simply uploaded the arial.ttf file from my Windows XP machine to my website and it worked just fine.

Here is a code snippet from the file that does it:

[code]var $font = ‘arial.ttf’;

$textbox = imagettfbbox($font_size, 0, $this->font, $code) or die(‘Error in imagettfbbox function’);
$x = ($width - $textbox[4])/2;
$y = ($height - $textbox[5])/2;
imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die(‘Error in imagettftext function’);

deansfurniture5 and pangea33, thanks, that worked

I seem to be getting much crappier rendering in the image than I do in the browser.

Is this a common problem, with a common solution?

I don’t honestly know the answer to that. It seems to me that the quality on the image shouldn’t be much worse, but it’s especially hard to say without knowing what your results look like compared side by side

Hm, I’m not sure. After looking at the documentation, I couldn’t find anything. imagepng() is better than imagejpeg(), but you’re already doing that…

For 30% more diskspace, 30% more bandwidth, and $40 off use promo code [color=#CC0000]THEFULLMONTY[/color]

Thanks again, I don’t want to take a lot of your time, but graphics is admittedly a weakness of mine… somebody else wrote the initial script, and I’ve modified it to include the text

This is the regular php page (html output)

and the imagemap