By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,730 Members | 1,659 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,730 IT Pros & Developers. It's quick & easy.

GD center text on a image

P: n/a
The following works fine - but would like to center the text .

Whats the best way to do it ? .

<?php

$text=$kk[4];

if ($kk[4]=="") {$text="MAIN MENU"; $kk[1]="mainmenu";}

$img_name="images/zdefault.jpg"; $source=ImageCreateFromJPEG($img_name);

$white=imagecolorallocate($source,255,255,255);
$grey=imagecolorallocate($source,213,224,225);
$black=imagecolorallocate($source,0,0,0);

$font='arial.ttf';

imagettftext($source,28,0,12,39,$grey, $font, $text);

imagettftext($source,28,0,10,37,$black,$font,$text );

$new_name="cat/$kk[1].jpg";

ImageJPEG($source,$new_name);

imagedestroy($source);

?>

Dec 1 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
<comp.lang.php>
<Krustov>
<Fri, 1 Dec 2006 20:34:27 -0000>
<MP***********************@news.newsreader.com>
Whats the best way to do it ? .
The below seems to work ok .

It seems strange that such a common feature like a align L/C/R parimeter
should be left out of a text function .

<?php

$text=$kk[4];

if ($kk[4]=="") {$text="MAIN MENU"; $kk[1]="mainmenu";}

$img_name="images/zdefault.jpg"; $source=ImageCreateFromJPEG($img_name);

$grey=imagecolorallocate($source,213,224,225);
$black=imagecolorallocate($source,0,0,0);

$font='arial.ttf';

$bbox=imagettfbbox(28,$angle,$font,$text);

$textWidth=$bbox[2]-$bbox[0];

$z=$bbox[2]/2;

$x=320-$z;

$y=37;

imagettftext($source,28,0,$x+2,$y+2,$grey,$font,$t ext);

imagettftext($source,28,0,$x,$y,$black,$font,$text );

$new_name="cat/$kk[1].jpg";

ImageJPEG($source,$new_name);

imagedestroy($source);

?>
--
www.phpwhois.co.uk
Dec 1 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.