Get line width and height in pixels (PHP)

Is there any good function to calculate pixel width and height? Can imagettfbbox be used for this? I mean, what ttf file is needed for different fonts used by different browsers?

thank

+5
source share
2 answers

Since PHP runs on the server, there is no way to do this using PHP. The text size depends on the operating system, browser (and browser settings, such as scaling) of the client. However, you can use javascript to get the size of the element after rendering it.

height = document.getElementById("elementId").style.height; // Will return 176px for example
width = document.getElementById("elementId").style.width; // Will return 176px for example

Hope this helps

+2
source

(imagefontwidth imagefontheight), , ( ). / , , .

, , .

, .

0

All Articles