Accurax Posted June 9, 2007 Share Posted June 9, 2007 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 :) Quote Link to comment https://forums.phpfreaks.com/topic/54866-solved-problem-centering-gd-text/ Share on other sites More sharing options...
Accurax Posted June 9, 2007 Author Share Posted June 9, 2007 figured it out... I was using the incorrect function for .ttf fonts Quote Link to comment https://forums.phpfreaks.com/topic/54866-solved-problem-centering-gd-text/#findComment-271368 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.