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([