Skip to content

Commit

Permalink
fixed toBlob to specify mineType and quality. close #1674
Browse files Browse the repository at this point in the history
  • Loading branch information
kawamataryo committed Nov 24, 2023
1 parent 47e8d20 commit 353a51d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Node.ts
Expand Up @@ -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);
}
Expand Down
20 changes: 20 additions & 0 deletions test/unit/Stage-test.ts
Expand Up @@ -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();
Expand Down

0 comments on commit 353a51d

Please sign in to comment.