开发者

get text length in px, php [duplicate]

开发者 https://www.devze.com 2023-01-15 21:56 出处:网络
This question already has an answer here: Closed 12 years ago. Possible Duplicate: PHP Accurate Font Width开发者_JAVA技巧
This question already has an answer here: Closed 12 years ago.

Possible Duplicate:

PHP Accurate Font Width 开发者_JAVA技巧

For example I have Arial font (22px size) text: "my name is lola" and how get this text length in pixels? (PHP languages)


well normaly you should be able to, make sure it has some wrapping tags like a span tag and use .width() function in jquery to get the width in pixels

http://api.jquery.com/width/

Edit: it's not php but it's the only possible way i know of doing this


... it depends:)

so i wont get downvoted more than i already had..without getting a comment: it depends on:

  • the used font

  • the OS where this font is used (the font renderer on linux is produces slightly different results that the one on windows, and probaly the same rule applies on OSX)

  • wherever you are using antialising and what kind of antialising is used

  • wherever the font is bold or not

  • the output medium (printed fonts are not identical to displayed font because of printer characteristics)

  • the letter spacing

As a solution you may use GD to render the text into a surface, and try to crop it..

0

精彩评论

暂无评论...
验证码 换一张
取 消