PHP GD true type fonts


 

PHP GD true type fonts

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

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

<?php

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");

imagepng($img);

?>

After running the program you will get the following output

Ads