Home Tutorial Php Phpgd PHP GD imagettfbox

 
 

Share on Google+Share on Google+
PHP GD imagettfbox
Posted on: November 11, 2009 at 12:00 AM
Advertisement
This example shows how to display imagettfbox in php gd.

<?php

$im = imagecreatetruecolor(300, 150);

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

$red = imagecolorallocate($im, 255, 0, 0);

imagefilledrectangle($im, 0, 0, 299, 299, $red);

$font = 'C:/WINNT/Fonts/arial.ttf';

$bbox = imagettfbbox(10, 45, $font, 'PHP version ' . phpversion());

$x = $bbox[0] + (imagesx($im) / 2) - ($bbox[4] / 2) - 25;

$y = $bbox[1] + (imagesy($im) / 2) - ($bbox[5] / 2) - 5;

imagettftext($im, 10, 45, $x, $y, $black, $font, 'PHP version ' . phpversion());

$bbox = imagettfbbox(10, 45, $font, 'Zend Engine version ' . zend_version());

$x = $bbox[0] + (imagesx($im) / 2) - ($bbox[4] / 2) + 10;

$y = $bbox[1] + (imagesy($im) / 2) - ($bbox[5] / 2) - 5;

imagettftext($im, 10, 45, $x, $y, $black, $font, 'Zend Engine version ' . zend_version());

header('Content-type: image/png');

imagepng($im);

imagedestroy($im);

?>

After running the program you will get the following output

Advertisement

Related Tags for PHP GD imagettfbox:


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.

Posted on: November 11, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com