Skip to content

@mbtech-nl/bitmap / scaleBitmap

Function: scaleBitmap()

ts
function scaleBitmap(bitmap: LabelBitmap, targetHeight: number): LabelBitmap;

Defined in: transform.ts:171

Resize a bitmap to a target height while preserving aspect ratio.

Uses nearest-neighbour sampling — appropriate for 1bpp output where any smoothing would muddy the result. For pre-rasterisation resizing, scale the source RGBA image instead and pass the result to renderImage.

Parameters

ParameterTypeDescription
bitmapLabelBitmapSource bitmap.
targetHeightnumberDesired height in pixels (positive integer).

Returns

LabelBitmap

A new bitmap. Width is computed as round(srcW * targetHeight / srcH), floored to a minimum of 1.

Throws

If targetHeight is not a positive integer.

Example

ts
const fitted = scaleBitmap(logo, 64);

Released under the MIT License.