Add export of canvas with mask as alpha channel

Introduces a new method to export the flattened canvas with the mask applied as the alpha channel. Updates UI actions to allow previewing, copying, and saving the image with mask alpha, and ensures node previews use the new export method. This enhances workflows that require the mask to be embedded as transparency in the output image.
This commit is contained in:
Dariusz L
2025-06-29 21:26:53 +02:00
parent 0bb54a0a6d
commit abb0f8ef53
3 changed files with 150 additions and 2 deletions

View File

@@ -197,6 +197,13 @@ export class Canvas {
return this.canvasLayers.getFlattenedCanvasAsBlob();
}
/**
* Eksportuje spłaszczony canvas z maską jako kanałem alpha
*/
async getFlattenedCanvasWithMaskAsBlob() {
return this.canvasLayers.getFlattenedCanvasWithMaskAsBlob();
}
/**
* Importuje najnowszy obraz
*/
@@ -212,6 +219,7 @@ export class Canvas {
* Uruchamia edytor masek
*/
async startMaskEditor() {
// Dla edytora masek używamy zwykłego spłaszczonego obrazu bez alpha
const blob = await this.canvasLayers.getFlattenedCanvasAsBlob();
if (!blob) {
log.warn("Canvas is empty, cannot open mask editor.");
@@ -446,7 +454,8 @@ export class Canvas {
this.saveState();
const new_preview = new Image();
const blob = await this.canvasLayers.getFlattenedCanvasAsBlob();
// Użyj nowej metody z maską jako kanałem alpha
const blob = await this.canvasLayers.getFlattenedCanvasWithMaskAsBlob();
if (blob) {
new_preview.src = URL.createObjectURL(blob);
await new Promise(r => new_preview.onload = r);