toCanvas

API reference for the "toCanvas" method.

Converts a CanvaImageBlob into an HTMLCanvasElement.

Usage

const { imageHelpers } = window.canva;
const canva = window.canva.init();
canva.onReady(async (opts) => {
// Convert a CanvaElement into a CanvaImageBlob
const image = await imageHelpers.fromElement(opts.element);
// Convert the CanvaImageBlob into an HTMLCanvasElement
const canvas = await imageHelpers.toCanvas(image);
// Do something with the result
console.log(canvas);
});

Parameters

Name

Type

Required

Description

image

CanvaImageBlob

Yes

The CanvaImageBlob to convert into an HTMLCanvasElement.

size

object

No

The dimensions of the HTMLCanvasElement. If null, the dimensions of the CanvaImageBlob are used.

size.height

number

No

The height of the HTMLCanvasElement, in pixels.

size.width

number

No

The width of the HTMLCanvasElement, in pixels.

Returns

Promise<HTMLCanvasElement>