How to determine the length (in pixels) of a string being rendered on a web page?

前端 未结 5 634
盖世英雄少女心
盖世英雄少女心 2020-12-14 17:19

If I know the font size (12) and the font family (calibri), is there a way to determine the length (in pixels) a given string will take after it will be rendered? I am absol

5条回答
  •  萌比男神i
    2020-12-14 17:45

    Use the PHP function imagettfbbox to get the size of the bounding box for the given string.

    On the other hand you can use also javascript to manipulate SVG images in case you would like to handle it on the client side. That way it wouldn't even matter if the client had the specified font or not...

提交回复
热议问题