Issue #803 - Reuse downloadCanvas_ to download single frame canvas

This commit is contained in:
juliandescottes 2018-06-09 14:12:18 +02:00 committed by Julian Descottes
parent 594d748146
commit 8662ab65ad

View File

@ -151,9 +151,9 @@
}; };
// Used and overridden in casper integration tests. // Used and overridden in casper integration tests.
ns.PngExportController.prototype.downloadCanvas_ = function (canvas) { ns.PngExportController.prototype.downloadCanvas_ = function (canvas, name) {
// Generate file name // Generate file name
var name = this.piskelController.getPiskel().getDescriptor().name; name = name || this.piskelController.getPiskel().getDescriptor().name;
var fileName = name + '.png'; var fileName = name + '.png';
// Transform to blob and start download. // Transform to blob and start download.
@ -223,15 +223,13 @@
ns.PngExportController.prototype.onDownloadSelectedFrameClick_ = function (evt) { ns.PngExportController.prototype.onDownloadSelectedFrameClick_ = function (evt) {
var frameIndex = this.piskelController.getCurrentFrameIndex(); var frameIndex = this.piskelController.getCurrentFrameIndex();
var name = this.piskelController.getPiskel().getDescriptor().name; var name = this.piskelController.getPiskel().getDescriptor().name;
var fileName = name + '-' + (frameIndex + 1) + '.png';
var canvas = this.piskelController.renderFrameAt(frameIndex, true); var canvas = this.piskelController.renderFrameAt(frameIndex, true);
var zoom = this.exportController.getExportZoom(); var zoom = this.exportController.getExportZoom();
if (zoom != 1) { if (zoom != 1) {
canvas = pskl.utils.ImageResizer.resize(canvas, canvas.width * zoom, canvas.height * zoom, false); canvas = pskl.utils.ImageResizer.resize(canvas, canvas.width * zoom, canvas.height * zoom, false);
} }
pskl.utils.BlobUtils.canvasToBlob(canvas, function(blob) { var fileName = name + '-' + (frameIndex + 1) + '.png';
pskl.utils.FileUtils.downloadAsFile(blob, fileName); this.downloadCanvas_(canvas, fileName);
});
}; };
})(); })();