Reference saveCanvas()

saveCanvas()

Saves the current canvas as an image.

By default, saveCanvas() saves the canvas as a PNG image called untitled.png.

The first parameter, filename, is optional. It's a string that sets the file's name. If a file extension is included, as in saveCanvas('drawing.png'), then the image will be saved using that format.

The second parameter, extension, is also optional. It sets the files format. Either 'png', 'webp', or 'jpg' can be used. For example, saveCanvas('drawing', 'jpg') saves the canvas to a file called drawing.jpg.

Note: The browser will either save the file immediately or prompt the user with a dialogue window.

Examples

Syntax

saveCanvas(selectedCanvas, [filename], [extension])
saveCanvas([filename], [extension])

Parameters

selectedCanvas
p5.Framebuffer|p5.Element|HTMLCanvasElement:

reference to a specific HTML5 canvas element.

filename
String:

file name. Defaults to 'untitled'.

extension
String:

file extension, either 'png', 'webp', or 'jpg'. Defaults to 'png'.

Notice any errors or typos? Please let us know. Please feel free to edit src/image/image.js and open a pull request!

Related References