measureTextHeight
Call Signature
measureTextHeight(
font,text,maxWidth?):number
Defined in: plugins/plugin-print/dist/esm/measure-text.d.ts:70
Measures the height of text when printed with font, wrapped at
maxWidth like print does. Every line break starts a new line, so
"a\n\nb" is three lines high, and leading or trailing line breaks add
empty lines too.
Parameters
font
BmFont
a bitmap font loaded with loadFont, or a font loaded with
loadTTF
text
string
the text to measure
maxWidth?
number
the width to wrap the text at. Without it the text only breaks at newlines.
Returns
number
the height in pixels: the number of lines, including empty ones, times the font’s line height
Example
import { measureTextHeight } from "jimp";import { loadTTF } from "jimp/load-ttf";
const font = await loadTTF("fonts/Inter-Regular.ttf");
measureTextHeight(font, "Hello world!", 100, { size: 32 }); // 77.4375Call Signature
measureTextHeight(
font,text,maxWidth,options):number
Defined in: plugins/plugin-print/dist/esm/measure-text.d.ts:71
Measures the height of text when printed with font, wrapped at
maxWidth like print does. Every line break starts a new line, so
"a\n\nb" is three lines high, and leading or trailing line breaks add
empty lines too.
Parameters
font
a bitmap font loaded with loadFont, or a font loaded with
loadTTF
text
string
the text to measure
maxWidth
number | undefined
the width to wrap the text at. Without it the text only breaks at newlines.
options
for loadTTF fonts, the size, and the lineHeight and
letterSpacing you print with
letterSpacing?
number
lineHeight?
number
size
number
Returns
number
the height in pixels: the number of lines, including empty ones, times the font’s line height
Example
import { measureTextHeight } from "jimp";import { loadTTF } from "jimp/load-ttf";
const font = await loadTTF("fonts/Inter-Regular.ttf");
measureTextHeight(font, "Hello world!", 100, { size: 32 }); // 77.4375