Skip to main content
Module

x/canvas/mod.ts>EmulatedCanvas2D

Canvas API for Deno, ported from canvaskit-wasm (Skia).
Latest
interface EmulatedCanvas2D
import { type EmulatedCanvas2D } from "https://deno.land/x/canvas@v1.4.1/mod.ts";

Properties

width: number
height: number

Methods

dispose(): void

Cleans up all resources associated with this emulated canvas.

decodeImage(bytes: ArrayBuffer | Uint8Array): Image

Decodes an image with the given bytes.

getContext(type: "2d"): EmulatedCanvas2DContext

Returns an emulated canvas2d context if type == '2d', null otherwise.

getContext(type: string): null
loadFont(bytes: ArrayBuffer | Uint8Array, descriptors: Record<string, string>): void

Loads the given font with the given descriptors. Emulates new FontFace().

registerFont(src: string, descriptors: object): void

Registers a font into Canvas. (node-canvas compatibility)

makePath2D(str?: string): EmulatedPath2D

Returns an new emulated Path2D object.

toDataURL(codec?: string, quality?: number): string

Returns the current canvas as a base64 encoded image string.

toBuffer(mimeType?: "image/png" | "image/jpeg"): Uint8Array

Returns Buffer containing Image data.

getRawBuffer(
x: number,
y: number,
width: number,
height: number,
): Uint8Array

Returns raw buffer, pointing to WASM memory, of underlying RGBA data with Zero Copying.