Their is a simple way round this that I came up with. If I pass in the length of the section where the image is going to be then check the length of the text created by GD compare if the text's width is equal to the section width it does this and if it isn't the font size is reduced by one and the ypos is reduced by 0.5 to ensure it is still centred.
Here is the code
while ($width > $settings->sectionWidth)
{
$settings->fontSize -= 1;
$bbox = imagettfbbox($settings->fontSize, 0, $font_path, $settings->data);
$width = abs($bbox[4] - $bbox[0]);
$settings->yPos -= 0.5;
}