Garry's Mod Wiki

Garry's Mod Wiki

  number, number surface.GetTextSize( string text )

Description

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

Does not take into account new lines, the returned height is for the entire font (as specified by the font), not maximum of individual characters.

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 text = "Hello World" local width, height = surface.GetTextSize( text ) 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.

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

This site is a community mirror of the official Garry's Mod wiki.. This site is not maintained by Facepunch Studios.

Page content is automatically updated twice a day. Edits and history are not available.

Last Parsed: Loading...