mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
fix(api): stop palette-quantising PNG output across image routes (#716)
resolveOutputFormat handed every route a default quality of 95, and Sharp reads quality on PNG as palette quantisation, so every PNG through the factory-route family came back dithered and often bigger. quality is now optional and stays undefined for PNG unless a caller passes an explicit override; smart-crop's user-chosen quality still quantises on request. Two branches bypassed the resolver and carried their own copy of the bug, both fixed: image-pad hardcoded quality 95 for transparent padding, replace-color hardcoded quality 100 when forcing PNG for transparency. pixelate drops the local special case #709 added for the same bug. Four new integration oracles on >256-colour inputs, each watched failing against the old code. Fixes #710
This commit is contained in:
@@ -15,12 +15,15 @@ describe("resolveOutputFormat", () => {
|
||||
expect(result.quality).toBe(95);
|
||||
});
|
||||
|
||||
it("detects PNG input and returns png config", async () => {
|
||||
it("detects PNG input and returns png config with no quality", async () => {
|
||||
const result = await resolveOutputFormat(PNG, "image.png");
|
||||
expect(result.format).toBe("png");
|
||||
expect(result.extension).toBe("png");
|
||||
expect(result.contentType).toBe("image/png");
|
||||
expect(result.quality).toBe(95);
|
||||
// Sharp reads `quality` on PNG as "quantise to a palette", so a default
|
||||
// quality silently dithered every PNG that passed through (issue #710).
|
||||
// Only an explicit override may request that.
|
||||
expect(result.quality).toBeUndefined();
|
||||
});
|
||||
|
||||
it("detects WebP input and returns webp config", async () => {
|
||||
@@ -37,6 +40,8 @@ describe("resolveOutputFormat", () => {
|
||||
expect(result.format).toBe("png");
|
||||
expect(result.extension).toBe("png");
|
||||
expect(result.contentType).toBe("image/png");
|
||||
// The fallback produces PNG too, so it gets the same lossless treatment.
|
||||
expect(result.quality).toBeUndefined();
|
||||
});
|
||||
|
||||
it("respects quality override for lossy formats", async () => {
|
||||
|
||||
Reference in New Issue
Block a user