Jump to content

font width outside of imagettftext to get imagefontwidth


redbrad0

Recommended Posts

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");

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.