Jump to content

Get string length (In pixels?)


RadGH

Recommended Posts

I want to truncate a string that will not fit into a table and append "..." to the end. Currently I just cut it off at 10 characters, but if you see the example below you'll see why that doesn't work:

 

QXQXQXQXQX

IJIJIJIJIJ

 

Is there a way (presumably using GD) to get the length of a string in pixels? I thought about writing a string to an image as I would be able to change the font and size, but I don't see an option to have the size of the image automatically stretched to fit.

 

So, is this possible, or is there an alternative solution? I've always been curious how applications were able to detect a font's actual width...

Link to comment
https://forums.phpfreaks.com/topic/124440-get-string-length-in-pixels/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.