redbrad0 Posted January 10, 2009 Share Posted January 10, 2009 I am trying to get the width of each character so I can write the text to the middle of the screen. The problem is, there is a big difference if in the imagettftext i set the font size from 10 to 50. How can I grab the accurate font width depending on the font size? $font_file = "cour.ttf"; $font_black = imagecolorresolve($im, 0, 0, 0); $font = imageloadfont($font_file); // Font size should be set here I am guessing $text_width = imagefontwidth($font); imagettftext($image, 10, 0, 10, 30, $font_black, $font_file, "size 10"); imagettftext($image, 40, 0, 10, 30, $font_black, $font_file, "size 40"); Link to comment https://forums.phpfreaks.com/topic/140281-font-width-outside-of-imagettftext-to-get-imagefontwidth/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.