Garry's Mod Wiki

surface.GetTextSize

number, number surface.GetTextSize( string text )

Description

Returns the width and height (in pixels) of the given text, but only if the font has been set with surface.SetFont.

Arguments

1 string text
The string to check the size of.

Returns

1 number
Width of the provided text
2 number
Height of the provided text

Example

Prints out the size of "Hello World" in the Trebuchet24 font.

surface.SetFont("Trebuchet24") local message = "Hello World" local width, height = surface.GetTextSize(message) print("Text width: " .. width .. ", text height: " .. height)
Output: Text width: 100, text height: 24

Example

Get text height very quickly. No tables or spare variables used.

local message = "Hello World" surface.SetFont("Trebuchet24") local height = select(2, surface.GetTextSize(message)) print(height)
Output: 24

Page Links


Special Pages


Wikis

?

Render Time: 34ms

DB GetPage 4
Generate Html 8
SaveChanges (1) 8
Render Body 0
Render Sidebar 12