From 353a51dae4658ee1376424843068729c15e4f00b Mon Sep 17 00:00:00 2001 From: kawamataryo Date: Fri, 24 Nov 2023 19:28:21 +0900 Subject: [PATCH] fixed toBlob to specify mineType and quality. close #1674 --- src/Node.ts | 2 +- test/unit/Stage-test.ts | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Node.ts b/src/Node.ts index c7048e6f3..dd044e473 100644 --- a/src/Node.ts +++ b/src/Node.ts @@ -2091,7 +2091,7 @@ export abstract class Node { this.toCanvas(config).toBlob((blob) => { resolve(blob); callback?.(blob); - }); + }, config?.mimeType, config?.quality); } catch (err) { reject(err); } diff --git a/test/unit/Stage-test.ts b/test/unit/Stage-test.ts index 354a51113..76f236781 100644 --- a/test/unit/Stage-test.ts +++ b/test/unit/Stage-test.ts @@ -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();