MCPcopy
hub / github.com/processing/p5.js / save

Method save

src/image/p5.Image.js:1449–1478  ·  view source on GitHub ↗

* Saves the image to a file. * * By default, `img.save()` saves the image 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 * `img.save('drawing.png')`, then

(filename, extension)

Source from the content-addressed store, hash-verified

1447 * }
1448 */
1449 save(filename, extension) {
1450 if (this.gifProperties) {
1451 encodeAndDownloadGif(this, filename);
1452 } else {
1453 let htmlCanvas = this.canvas;
1454 extension =
1455 extension ||
1456 _checkFileExtension(filename, extension)[1] ||
1457 'png';
1458
1459 let mimeType;
1460 switch (extension) {
1461 default:
1462 //case 'png':
1463 mimeType = 'image/png';
1464 break;
1465 case 'webp':
1466 mimeType = 'image/webp';
1467 break;
1468 case 'jpeg':
1469 case 'jpg':
1470 mimeType = 'image/jpeg';
1471 break;
1472 }
1473
1474 htmlCanvas.toBlob(blob => {
1475 downloadFile(blob, filename, extension);
1476 }, mimeType);
1477 }
1478 }
1479
1480 async toBlob() {
1481 return new Promise(resolve => {

Callers 11

keyTypedFunction · 0.80
files.jsFile · 0.80
_ensureCanvasMethod · 0.80
setMethod · 0.80
pushMethod · 0.80
clearMethod · 0.80
_getTintedImageCanvasMethod · 0.80
setMethod · 0.80
pushMethod · 0.80
pathToContextFunction · 0.80

Calls 4

_checkFileExtensionFunction · 0.90
downloadFileFunction · 0.90
encodeAndDownloadGifFunction · 0.85
toBlobMethod · 0.80

Tested by

no test coverage detected