Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any way to calculate the pixel length of a string?

Tags:

string

php

image

gd

I'm using the GD library for PHP, and using functions like imagestring() and imagestringup() to add text to pictures. I am using the built-in fonts with latin2 encoding. Is there a way, with a given string, to calculate the length (in pixels) of the string?

I want to calculate the length in pixels of the strings because the strings are variable and I want to make sure the string doesn't overflow the area I want to put it in.

Thanks for your help.

like image 565
trip0d199 Avatar asked Nov 16 '09 12:11

trip0d199


1 Answers

imagettfbbox() does that: http://www.php.net/manual/en/function.imagettfbbox.php

like image 84
Pekka Avatar answered Sep 27 '22 21:09

Pekka