monkeypaw201 Posted February 28, 2009 Share Posted February 28, 2009 Is there any way to calculate the pixel width of a word if given the font and the size? Quote Link to comment https://forums.phpfreaks.com/topic/147247-calculating-pixel-width-of-a-word/ Share on other sites More sharing options...
RussellReal Posted February 28, 2009 Share Posted February 28, 2009 well yes if you use a font with fixed widths but there is another way that I just found out recently aswell for images.. the function is imagettfbox Quote Link to comment https://forums.phpfreaks.com/topic/147247-calculating-pixel-width-of-a-word/#findComment-773021 Share on other sites More sharing options...
monkeypaw201 Posted February 28, 2009 Author Share Posted February 28, 2009 Well if its a monospace font.. the font size would define the width and height right? In which case you could just count the number of letter and multiply by the font size.. Quote Link to comment https://forums.phpfreaks.com/topic/147247-calculating-pixel-width-of-a-word/#findComment-773065 Share on other sites More sharing options...
haku Posted February 28, 2009 Share Posted February 28, 2009 It's not going to work. Each browser renders fonts in their own way, even when the font size is explicitly set. So thew word 'word', set with a font-size of 14px, is going to be different widths in each browser. Quote Link to comment https://forums.phpfreaks.com/topic/147247-calculating-pixel-width-of-a-word/#findComment-773087 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.