Truetype fonts in php


#1

(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:

/usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf

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

Alternatively:

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

#2

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]

fidgeting.net


#3

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’);
[/code]


#4

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?


#5

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


#6

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]

fidgeting.net


#7

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)

http://coolgeek.dreamhosters.com/arg/19

and the imagemap

http://coolgeek.dreamhosters.com/extarg/19