Skip to content

@mbtech-nl/bitmap / measureText

Function: measureText()

ts
function measureText(text: string, options?: TextRenderOptions): {
  heightPx: number;
  widthPx: number;
};

Defined in: font/render.ts:129

Compute the dimensions a renderText call would produce, without allocating a bitmap. Empty strings return { widthPx: 0, heightPx }.

Parameters

ParameterType
textstring
optionsTextRenderOptions

Returns

ts
{
  heightPx: number;
  widthPx: number;
}

heightPx

ts
heightPx: number;

widthPx

ts
widthPx: number;

Example

ts
const { widthPx, heightPx } = measureText('SKU-1234', { scaleX: 2 });

Released under the MIT License.