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
reference to a specific HTML5 canvas element.
file name. Defaults to 'untitled'.
file extension, either 'png', 'webp', or 'jpg'. Defaults to 'png'.