Pick a small font size, and use [man]imagettfbox[/max] to see how big a box it needs. If it can fit within the bounds of the rectangle, increase the size a bit and try again. Repeat until it gets too big to fit, then go back down one step and that's the size you want.