Skip to content

Commit

Permalink
✨ Implement unique function for all canvas data type
Browse files Browse the repository at this point in the history
  • Loading branch information
Xen0Xys committed Jun 12, 2024
1 parent 8779f6d commit 45cab01
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/js/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,35 @@ export let View = (function () {
});
}

/**
* Return Blob corresponding to the current view
*/
View.prototype.getCanvasBlob = async function (imgType, width, height, withLogo=true) {
const c = await this.getCanvas(imgType, width, height, withLogo);
return new Promise((resolve, reject) => {
c.toBlob(blob => {
if (blob) {
resolve(blob);
} else {
reject(new Error('Canvas toBlob failed'));
}
});
});
}

View.prototype.getViewData = async function (dataType, imgType, width, height, withLogo=true){
switch (dataType) {
case "url":
return await this.getCanvasDataURL(imgType, width, height, withLogo);
case "arraybuffer":
return await this.getCanvasArrayBuffer(imgType, width, height, withLogo);
case "blob":
return await this.getCanvasBlob(imgType, width, height, withLogo);
default:
throw new Error("Unknown data type: " + dataType);
}
}

View.prototype.selectLayer = function (layer) {
if (!this.imageLayers.has(layer)) {
console.warn(layer + ' does not exists. So cannot be selected');
Expand Down

0 comments on commit 45cab01

Please sign in to comment.