Forum Moderators: coopster

Message Too Old, No Replies

write text in the centre of an image

how to write text in centre

         

phparion

11:10 am on Jul 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



hi

i have the following code to write text on an image

$myImage = imagecreatefromjpeg('certificate.jpg');

$black=imagecolorallocate($myImage, 0, 0 ,0);
imagefttext($myImage, 16, 0, 250, 140, $black, "arialbd.ttf",$_REQUEST['cname']);
imagefttext($myImage, 12, 0, 290, 160, $black, "arialbd.ttf","STATE");
imagefttext($myImage, 12, 0, 300, 180, $black, "arialbd.ttf","COUNTRY");

header("Content-type: image/jpeg");
imagejpeg($myImage);

but if the name is say,

charlie it will become in the middle of the image but if the name is long like Angelina Jolie it starts at the fixed width and height and is pushed towards the right side of the image..

i want that the script automatically writes the text in the exact centre of the image,
like in html we do

<center>name</center> so whatever the text length is it will come in the centre of the page..

is there any option in php to write the text in the centre of the image?

coopster

12:53 pm on Jul 15, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You need to divide the width and height by 2 to find the center. I found a thread on PHP with images [webmasterworld.com] that describes the concept with a working example.