Aligning Text Within a Fixed Space Using imageTTFbbox() : Text Align : Graphics Image PHP Source Code


PHP Source Code » Graphics Image » Text Align »

 

Aligning Text Within a Fixed Space Using imageTTFbbox()



<?php
header("Content-type: image/gif");
$height = 100;
$width = 200;
$fontsize = 50;
if ! isset $text ) )
    $text = "www.navioo.com";
$image = imagecreate$width, $height );
$red = imagecolorallocate($image, 255,0,0);
$blue = imagecolorallocate($image, 0,0,255 );
$font = "ARIALBD.TTF";
$textwidth = $width;
$textheight;

while ){
    $box = imageTTFbbox$fontsize, 0, $font, $text );
    $textwidth =  abs$box[2] );
    $textbodyheight = abs($box[7]) )-2;
    if $textwidth < $width - 20 )
        break;
    $fontsize--;
}
$gifXcenter = (int) ( $width/);
$gifYcenter = (int) ( $height/);
imageTTFtext($image, $fontsize, 0,(int) ($gifXcenter-($textwidth/2)),(int)($gifYcenter+(($textbodyheight)/2) ),
             $blue, $font, $text );
imagegif($image);
?>

           
       



HTML code for linking to this page:

Follow Navioo On Twitter

PHP Source Code

 Navioo Graphics Image
» Text Align