Function: getTextPixelWidth()
ts
function getTextPixelWidth(text, options): number;Calculates the pixel width of the given text in the specified font.
Parameters
| Parameter | Type | Description |
|---|---|---|
text | string | The text to calculate the width of. |
options | { font?: string; fontFamily?: string; fontSize?: string | number; fontWeight?: string | number; } | Options for the font. |
options.font? | string | The font string to use, e.g. Arial. |
options.fontFamily? | string | The name of the font family, e.g. sans-serif. |
options.fontSize? | string | number | The size of the font in pixels. |
options.fontWeight? | string | number | The weight of the font, e.g. bold. |
Returns
number
The pixel width of the text in the specified font.
Example
ts
getTextPixelWidth('Hello, World!', { fontFamily: 'Arial', fontSize: 20 }) // => 123Since
1.0.0