Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/skia_canvas/src/canvas.ts>Canvas

Fast HTML Canvas API implementation for Deno using Google Skia
Latest
class Canvas
import { Canvas } from "https://deno.land/x/skia_canvas@0.5.8/src/canvas.ts";

Canvas is an offscreen surface that can be drawn to.

Internally it uses Skia's SkSurface and raster backend.

API is mostly compatible with the Web's OffscreenCanvas API, however we also have some non-standard methods such as save.

Constructors

new
Canvas(
width: number,
height: number,
gpu?,
)

Properties

readonly
_unsafePointer: Deno.PointerValue
readonly
gpu: boolean

Whether Canvas is GPU backed

height: number
width: number
[_gpu]: boolean
[_height]: number
[_width]: number

Methods

encode(format?: ImageFormat, quality?): Uint8Array

Encode the canvas image into a buffer in specified format and quality.

Only for GPU backed: Flushes all draw calls, call before swap

Returns the Rendering Context of the canvas

readPixels(
x?,
y?,
width?: number,
height?: number,
into?: Uint8Array,
colorSpace?: ColorSpace,
): Uint8Array

Read pixels from the canvas into a buffer.

resize(width: number, height: number): void

Resizes the Canvas to the specified dimensions

save(
path: string,
format?: ImageFormat,
quality?,
)

Save the canvas image to a file encoded in specified format and quality.

Quality is a factor between 0 and 100, where 100 is the best quality. It represents different factors for different formats.

toDataURL(format?: ImageFormat, quality?): string

Creates a data url from the canvas data

[Symbol.for("Jupyter.display")](): Record<string, string>