The save() function in p5.js is used to save to the file system by prompting a download to the computer. This function can be used to save text, images, JSON, CSV, wav, or HTML files. The default option is to save the current canvas as an image.
The first parameter of the function can be specified various values depending on the file to save. Examples include a pointer to the canvas element, an array of Strings, a JSON object, or an array, a p5.Table element for tables, a p5.Image element for images or a p5.SoundFile element for sounds.
Note: It is not recommended to call this function inside the
draw() loop, as it will prompt a new save dialog every draw call.
save( [objectOrFilename], [filename], [options] )
Parameters: This function accepts three parameter as mentioned above and described below.
- objectOrFilename: This is an Object or String that is used to denote the object to save or the filename (if saving the canvas). If an Object is provided, it will save the file depending upon the object and filename. It is an optional parameter.
- filename: It specifies the String that is used as the filename of the saved file. It is an optional parameter.
- options: It is a Boolean value or String which provides additonal options for the file to be saved. Incase of JSON files, a value of ‘true’ would save the JSON optimized for filesize, instead of readability. It is an optional parameter.
The examples below illustrate the save() function in p5.js:
Online editor: https://editor.p5js.org/
- What is the difference between --save and --save-dev in Node.js ?
- PHP | DOMDocument save() Function
- Mongoose | save() Function
- HTTP headers | Save-Data
- How to save an HTML 5 Canvas as an image on the server ?
- Save Files in ElectronJS
- What is the meaning of --save for NPM install ?
- How to auto-save data when application is offline in Angular 8?
- Save Pages as HTML in ElectronJS
- How to Make, Save, and Run a Simple VBScript Program?
- p5.Image save() Method
- How to get the function name inside a function in PHP ?
- PHP | imagecreatetruecolor() Function
- p5.js | year() function
- D3.js | d3.utcTuesdays() Function
- PHP | ImagickDraw getTextAlignment() Function
- PHP | Ds\Sequence last() Function