fixed toBlob to specify mineType and quality. close #1674

This commit is contained in:
kawamataryo 2023-11-24 19:28:21 +09:00
parent 47e8d20a52
commit 353a51dae4
2 changed files with 21 additions and 1 deletions

View File

@ -2091,7 +2091,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
this.toCanvas(config).toBlob((blob) => {
resolve(blob);
callback?.(blob);
});
}, config?.mimeType, config?.quality);
} catch (err) {
reject(err);
}

View File

@ -1368,6 +1368,26 @@ describe('Stage', function () {
}
});
it('toBlob with mimeType option using', async function () {
const stage = addStage();
const layer = new Konva.Layer();
stage.add(layer);
if (isBrowser) {
try {
const blob = await stage.toBlob({
mimeType: 'image/jpeg',
quality: 0.5,
});
assert.isTrue(blob instanceof Blob && blob.type === 'image/jpeg', "can't change type of blob");
} catch (e) {
console.error(e);
assert.fail('error creating blob');
}
}
});
it('check hit graph with stage listening property', function () {
var stage = addStage();
var layer = new Konva.Layer();