问题
I'm trying to display a number using GD. This number changes, so sometimes the width needs to change. Is there a way to calculate how wide the text will be so that I can dynamically set the width?
回答1:
Yes, you can find out the dimensions of a text using imagettfbbox() (or imageftbbox() if you're using Freetype).
来源:https://stackoverflow.com/questions/4485630/how-can-i-auto-adjust-the-width-of-a-gd-generated-image-to-fit-the-text