Share on Google+Share on Google+

PHP GD true type fonts

This example shows how to display true type fonts(TTF) in php gd.


define("WIDTH", 300);

define("HEIGHT", 100);

define("F_SIZE", 40);

define("F_ANGLE", 0);

define("F_FONT", "C:/WINNT/Fonts/arial.ttf");

$img = imagecreate(WIDTH, HEIGHT);

$white = imagecolorallocate($img, 255,255,255);

$black = imagecolorallocate($img, 0,0,0);

$start_x = 10;

$start_y = (int)HEIGHT/2;

$text = "True Fonts";

imagerectangle($img, 0,0,WIDTH-1,HEIGHT-1, $black);

imageTTFtext($img, F_SIZE, F_ANGLE, $start_x, $start_y, $black, F_FONT, $text);

header("Content-Type: image/png");



After running the program you will get the following output



Posted on: November 13, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.


Advertisement null