Jump to content

[SOLVED] Problem Centering GD text


Accurax

Recommended Posts

im trying to calculate the x value to insert into my imagettftext(); function so that the text becomes centered in my canvas.

 

heres my code so far

 

// define the path to the selected font
$font = $_GET['font'];

//get the phrase and calculate its width for centering
$phrase = stripslashes($_GET['phrase']);
$phr_len = strlen($phrase); 
$fnt_wid = imagefontwidth ($font);
$phr_wid = ($fnt_wid * $phr_len);

//calculate the x co-ordinate
$canvas_wid = 600 / 2;
$x1 = round(($canvas_wid - $phr_wid)/2);

 

I think the problem is something to do with the size of the font not being specied untill later in my script when i actually execute imagettftext();

 

But im not sure how to get around this..... my font size is to be fixed at 24 if thats any help.

 

Anybody got any ideas please?

 

Thankyou in advance guys  :) :)

Link to comment
https://forums.phpfreaks.com/topic/54866-solved-problem-centering-gd-text/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.