A dirty suggestion:
You can use GD::Image->stringTTF to get the bounds of a string printed on a GD Image. Maybe It will not be exact the
same size on a browser page but it might work. I use it to scale the text on PNG buttons in some code I wrote and posted at
ButtonFactory
/brother t0mas