如何自动调整GD生成的图像的宽度以适合文本? [英] How can I auto adjust the width of a GD-generated image to fit the text?

查看:38
本文介绍了如何自动调整GD生成的图像的宽度以适合文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用GD显示一个数字.此数字会更改,因此有时需要更改宽度.有没有一种方法可以计算文本的宽度,以便我可以动态设置宽度?

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?

推荐答案

是的,您可以使用 imageftbbox() (如果您使用的是Freetype).

Yes, you can find out the dimensions of a text using imagettfbbox() (or imageftbbox() if you're using Freetype).

这篇关于如何自动调整GD生成的图像的宽度以适合文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆