The following code shows how to get font width with imagefontwidth().
<?php echo 'Font width: ' . imagefontwidth(4); ?>
The code above generates the following result.