Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I programmatically determine what fonts I can use with GD?

Tags:

php

gd

I want to put text over an image using GD.

When I use

ImageTTFText($image, $fontSize, $fontRotation, 7, 22, $colorShadow, 'arial.ttf', $str);

I get

Warning: imagettftext() [function.imagettftext]: Could not find/open font in /home/index.php on line 17

Can I get PHP or GD to return a list of all available fonts per my system?

Thanks

Update

... or do I need to upload myself all the fonts myself that I wish GD to have access to?

like image 809
alex Avatar asked Mar 10 '26 18:03

alex


1 Answers

Replace "arial.ttf" with "./arial.ttf", because "arial.ttf" is an absolute path and you need a relative path. Read more on imagettftext here.

To answer your update, yes, you do need the font files in that directory. Here is a really cool site for finding fonts (like arial.ttf): http://www.1001freefonts.com/

Download a font file from there, put it in the folder of your script, and then replace "arial.ttf" with "./filename.ttf".

like image 169
Tom Avatar answered Mar 12 '26 06:03

Tom



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!