From b9e1671777bfc5749ebdaaa631f6c9bf00c525ee Mon Sep 17 00:00:00 2001 From: 134 Date: Fri, 3 Jul 2026 22:44:18 +0800 Subject: [PATCH] fix: apply scale diff masks as alpha --- lib/canvas/generate-image.ts | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/canvas/generate-image.ts b/lib/canvas/generate-image.ts index 1002ef17c..3443b2e8d 100644 --- a/lib/canvas/generate-image.ts +++ b/lib/canvas/generate-image.ts @@ -2804,7 +2804,7 @@ async function applyScaleAdjustPatchCompositeToImages(params: { }) .png({ compressionLevel: 6 }) .toBuffer(); - const patchMask = + const diffPatchMask = composite.maskMode === "diff" ? await buildLocalEditDiffCompositeMask({ composite: { @@ -2823,15 +2823,22 @@ async function applyScaleAdjustPatchCompositeToImages(params: { sourceBuffer: sourcePatchBuffer, width: workspaceBox.width, }) - : staticPatchMask; + : null; + const patchMask = diffPatchMask || staticPatchMask; if (!patchMask) { throw new Error("比例调整局部结果合成失败:无法生成合成蒙版"); } - const patchOverlayBuffer = await sharp(resizedGeneratedBuffer, { failOn: "none" }) - .ensureAlpha() - .composite([{ input: patchMask, blend: "dest-in" }]) - .png({ compressionLevel: 6 }) - .toBuffer(); + const patchOverlayBuffer = diffPatchMask + ? await sharp(resizedGeneratedBuffer, { failOn: "none" }) + .removeAlpha() + .joinChannel(diffPatchMask) + .png({ compressionLevel: 6 }) + .toBuffer() + : await sharp(resizedGeneratedBuffer, { failOn: "none" }) + .ensureAlpha() + .composite([{ input: patchMask, blend: "dest-in" }]) + .png({ compressionLevel: 6 }) + .toBuffer(); const mergedBuffer = await sharp(sourceBuffer, { failOn: "none" }) .ensureAlpha() .composite([