The functions imagegettfbbox(), imageftbbox(), etc. can be used for that. The user notes section for imagegettfbox() has, for example, a routine posted by webmaster at funfragforce dot de to center text on an image. I haven't tested it, but there are lots of other routines and functions posted, one of which should solve your problem or at least get you started.