Skip to content

Documentation / @ripl/canvas / canvasDrawImage

Function: canvasDrawImage() ​

canvasDrawImage(ctx, image, x, y, width?, height?): void

Defined in: canvas/src/utilities.ts:384

Draws an image onto a canvas context, sizing it to the given width and height.

A dimension given on its own is honoured and the other taken from the image's intrinsic size — the destination-rectangle form of drawImage needs both. Supplying neither draws at intrinsic size; supplying 0 draws nothing, which is what a zero-sized element asks for.

Parameters ​

ParameterTypeDescription
ctxCanvasRenderingContext2DThe native context to draw into.
imageCanvasImageSourceThe image source to draw.
xnumberDestination x coordinate.
ynumberDestination y coordinate.
width?numberDestination width, defaulting to the image's intrinsic width.
height?numberDestination height, defaulting to the image's intrinsic height.

Returns ​

void