fix: force PNG output for TIFF when alpha is required

Sharp's TIFF encoder silently strips the alpha channel, flattening
transparency against black. This caused border (corner radius, shadow),
beautify, and replace-color tools to produce wrong output for TIFF
inputs when the operation needs transparency. Remove TIFF from
ALPHA_FORMATS so these tools fall back to PNG output.
This commit is contained in:
SnapOtter
2026-05-13 11:37:45 +08:00
parent d22bebb8ad
commit 882ca2caf4
3 changed files with 3 additions and 3 deletions
+1 -1
View File
@@ -27,7 +27,7 @@ import { decompressSvgz, sanitizeSvg } from "../../lib/svg-sanitize.js";
import { createWorkspace } from "../../lib/workspace.js";
import { registerToolProcessFn } from "../tool-factory.js";
const ALPHA_FORMATS = new Set(["png", "webp", "avif", "tiff"]);
const ALPHA_FORMATS = new Set(["png", "webp", "avif"]);
function escapeXml(text: string): string {
return text
+1 -1
View File
@@ -146,7 +146,7 @@ export function registerBorder(app: FastifyInstance) {
}
const outputFormat = await resolveOutputFormat(inputBuffer, filename);
const ALPHA_FORMATS = new Set(["png", "webp", "avif", "tiff"]);
const ALPHA_FORMATS = new Set(["png", "webp", "avif"]);
const needsAlpha = settings.cornerRadius > 0 || settings.shadow;
if (needsAlpha && !ALPHA_FORMATS.has(outputFormat.format)) {
+1 -1
View File
@@ -75,7 +75,7 @@ export function registerReplaceColor(app: FastifyInstance) {
}
const outputFormat = await resolveOutputFormat(inputBuffer, filename);
const ALPHA_FORMATS = new Set(["png", "webp", "avif", "tiff"]);
const ALPHA_FORMATS = new Set(["png", "webp", "avif"]);
const needsAlpha = settings.makeTransparent;
const useFormat =
needsAlpha && !ALPHA_FORMATS.has(outputFormat.format)