save

Static save 

Source
pub static save: SaveInternalType
Expand description

Saves a given element(image, text, json, csv, wav, or html) to the client's computer. The first parameter can be a pointer to element we want to save. The element can be one of p5.Element,an Array of Strings, an Array of JSON, a JSON object, a p5.Table , a p5.Image, or a p5.SoundFile (requires p5.sound). The second parameter is a filename (including extension).The third parameter is for options specific to this type of object. This method will save a file that fits the given parameters. If it is called without specifying an element, by default it will save the whole canvas as an image file. You can optionally specify a filename as the first parameter in such a case. Note that it is not recommended to call this method within draw, as it will open a new save dialog on every render.

Examples

 // Saves the canvas as an image
 cnv = createCanvas(300, 300);
 save(cnv, 'myCanvas.jpg');

 // Saves the canvas as an image by default
 save('myCanvas.jpg');
 // Saves p5.Image as an image
 img = createImage(10, 10);
 save(img, 'myImage.png');
 // Saves p5.Renderer object as an image
 obj = createGraphics(100, 100);
 save(obj, 'myObject.png');
 let myTable = new p5.Table();
 // Saves table as html file
 save(myTable, 'myTable.html');

 // Comma Separated Values
 save(myTable, 'myTable.csv');

 // Tab Separated Values
 save(myTable, 'myTable.tsv');
 let myJSON = { a: 1, b: true };

 // Saves pretty JSON
 save(myJSON, 'my.json');

 // Optimizes JSON filesize
 save(myJSON, 'my.json', true);
 // Saves array of strings to text file with line breaks after each item
 let arrayOfStrings = ['a', 'b'];
 save(arrayOfStrings, 'my.txt');

Parameters

objectOrFilename? If filename is provided, will save canvas as an image with either png or jpg extension depending on the filename. If object is provided, will save depending on the object and filename (see examples above).

filename? If an object is provided as the first parameter, then the second parameter indicates the filename, and should include an appropriate file extension (see examples above).

options? Additional options depend on filetype. For example, when saving JSON, true indicates that the output will be optimized for filesize, rather than readability.