lmccart/p5.js — pull request #334 by therewasaguy (2014-08-22 21:39:41+00:00)
Title: One save() method to save them all

Here's what the documentation looks like so far... I've left out the file extension parameter, instead we can parse the extension from the filename. One thing I'm not sure of: when saving the canvas, the first parameter is the filename, but in all other cases the first parameter is the object to save.

....

Save an image, text, json, csv, wav, or html. Prompts download to the client's computer.

The default behavior is to save an image from the canvas. For example:

```
save()
save('myFile.jpg')
```

Alternately, the first parameter can be 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 paramaters. For example:

```
save(myTable, 'myTable.html') // Saves table as html file
save(myTable, 'myTable.csv',) // Comma Separated Values
save(myTable, 'myTable.tsv') // Tab Separated Values
```

```
save(myJSON, 'my.json') // Saves pretty JSON
save(myJSON, 'my.json', true) // Optimizes JSON filesize
```

````
save(img, 'my.png') // Saves pImage as a png image
save(arrayOfStrings, 'my.txt') // Saves strings to a text file with line breaks after each item in the array
```

Parameters

object/filename	[Object/String]: 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	[String]: 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	[Boolean/String]: Additional options depend on filetype. For example, when saving JSON, true indicates that the output will be optimized for filesize, rather than readability.