Fonts with GDLIB

GD and GD2 are useful libraries for creating graphics on-the-fly. Discuss your PHP GD and GD2 scripts here.

Moderators: onion2k, General Moderators

Post Reply
pickey
Forum Newbie
Posts: 9
Joined: Mon Feb 18, 2008 10:52 pm

Fonts with GDLIB

Post by pickey »

Hello All,


Am using below code :

header("Content-type: image/png");
$string = $_GET['text'];
$im = imagecreatefrompng("images/button1.png");
$orange = imagecolorallocate($im, 220, 210, 60);
$px = (imagesx($im) - 7.5 * strlen($string)) / 2;
imagestring($im, 3, $px, 9, $string, $orange);
imagepng($im);
imagedestroy($im);

Given above code I can not change Font Face what I can do is to change font size from 1 to 5 only.
How to go about it if I want to use different Font Face i.e. Verdana, Arial Rounded or it could be anything. I am using PNG images.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Fonts with GDLIB

Post by onion2k »

imagestring() is pretty awful for switching fonts. Try imagettftext() instead, that will let you use TTF fonts (any Windows font basically). You do need to have Postscript compiled into GD but most hosts have it, as does the standard PHP installer if you're working locally.
Post Reply