OptionaldensityNumber of pixels per grid ‘point’ (defaults to 1)
OptionalmatteBackground color to draw beneath transparent parts of the canvas
OptionalmsaaNumber of samples used for antialiasing each pixel. 0 and 1 both
mean one sample a pixel -- no multisampling.
OptionalpageWhich page to export, numbered from 1.
Left out, a single-page format encodes the current page -- the most
recently added one, which is what canvas.getContext() hands back --
and a format that gathers pages takes all of them. A negative number
counts from the end, so -1 is that same current page named explicitly.
A number past either end is a RangeError that names the page asked
for, not the index it resolved to.
OptionalpageWhich pages to gather, numbered from 1 and inclusive at both ends.
Left out, a format that gathers pages takes all of them. Negative
numbers count from the end, as RenderOptions.page does, so
[2, -1] is everything after the first page.
This is what separates an intro from the loop that follows it: two calls
over one canvas, each with its own loop, rather than one file that has
to compromise between them.
const intro = await canvas.toBuffer('webp', { fps: 30, pageRange: [1, 20], loop: 1 })
const cycle = await canvas.toBuffer('webp', { fps: 30, pageRange: [21, 60], loop: 0 })
It serves the paged documents as well -- { pageRange: [12, 18] } pulls
one chapter out of a long PDF, and a filename template such as
frame-{}.png writes only the frames named.
Naming both this and page is a TypeError: they answer the same
question differently. A bound past either end is a RangeError naming
the page asked for, an end before its start is a RangeError, and a
range given to a format that encodes a single page -- with no filename
template to write a sequence -- is a TypeError.
🧪 Not in the HTML Canvas standard.