Gets or sets the height of a canvas element on a document.
ReadonlyjpgThe canvas as JPEG bytes, as an ArrayBuffer.
No quality is passed, so the browser's own default applies rather than
the 0.92 the Node build uses. Call toBuffer("jpg", 0.8) to choose one.
ReadonlypagesEvery page added so far, oldest first, each as the context that draws it. The last entry is the current page.
🧪 Not in the HTML Canvas standard.
ReadonlypngThe canvas as PNG bytes -- toBuffer("png") with no arguments, and an
ArrayBuffer rather than Node's Buffer.
Gets or sets the width of a canvas element on a document.
Returns an object that provides methods and properties for drawing and manipulating images and graphics on a canvas element in a document. A context object includes information about colors, line widths, fonts, and other graphic parameters that can be drawn on a canvas.
The type of canvas to create. Skia Canvas only supports a 2-D context using canvas.getContext("2d")
The argument is required: the runtime returns null for anything other
than "2d", including no argument at all, so declaring it optional
promised a context that would not arrive.
Add a page, and return its drawing context.
Pages stay drawable once added, and which of them an export takes
depends on the format and the filename. PDF, TIFF, ICO and the three
animated formats gather every page into one file; the rest write the
current page alone, unless the filename passed to toFile contains
"{}", which writes one numbered file per page.
The size is a pair or nothing: omit both to keep the canvas's current size, or give both to resize the canvas for this page onward. Earlier pages keep the size they were created at. Passing only a width throws, rather than adding a page at a size nobody asked for.
🧪 Not in the HTML Canvas standard.
Add a page, and return its drawing context.
Pages stay drawable once added, and which of them an export takes
depends on the format and the filename. PDF, TIFF, ICO and the three
animated formats gather every page into one file; the rest write the
current page alone, unless the filename passed to toFile contains
"{}", which writes one numbered file per page.
The size is a pair or nothing: omit both to keep the canvas's current size, or give both to resize the canvas for this page onward. Earlier pages keep the size they were created at. Passing only a width throws, rather than adding a page at a size nobody asked for.
🧪 Not in the HTML Canvas standard.
Encode the canvas and hand the result to a callback as a Blob.
Callback-style and returning void, as the standard defines it, rather
than the promise the other exporters on this class return. type is a
mime type -- "image/png" -- not the bare format name they take.
A failed encode calls back with null rather than raising: the callback
has already been handed off by the time the encode runs.
Optionaltype: stringOptionalquality: numberThe encoded bytes, as an ArrayBuffer rather than Node's Buffer: this
comes from Blob.arrayBuffer(), and there is no Buffer in a page.
format defaults to PNG. A number in place of the options is read as
quality, as it is in the Node build.
Optionalformat: ExportFormatOptionaloptions: number | ExportOptionsformat accepts a bare extension ("png") or a mime type
("image/png"), and defaults to PNG as in the browser.
Optionalformat: stringOptionalquality: numberDownloads the canvas rather than writing a file: there is no filesystem
here, so filename names the download and the browser puts it wherever
downloads go.
A filename containing "{}" downloads every page as a zip archive
instead, one numbered file inside it -- the same "{}" that writes a
numbered sequence in Node. Page count alone does not trigger it: without
the braces this downloads the current page, as the other exporters do.
The archive is named by the archive option, defaulting to
"canvas.zip".
Zipping needs JSZip in your bundle. Without it the promise still resolves and nothing downloads -- the reason is logged to the console rather than thrown.
Optionaloptions: number | SaveOptions & { archive?: string }A data: URL. format defaults to PNG.
Optionalformat: ExportFormatOptionaloptions: number | ExportOptions
A canvas in the browser: a real
<canvas>element with this library's drawing and export API assigned onto it.Because it is the element, everything
HTMLCanvasElementoffers is there at runtime —toBlob,getContext,width,height— and the DOM types describe those. What this adds is the parts of the Node API the shim implements, with the return types the browser actually produces.