From 5b5767990bbe93a157bdb21dc221a5c83d9d090f Mon Sep 17 00:00:00 2001 From: SnapOtter Date: Mon, 11 May 2026 16:29:14 +0800 Subject: [PATCH] fix: tighten target-size compression tolerance from 5% to 1% The binary search exited early at 5% tolerance, producing output like 48.3KB for a 50KB target. Reducing to 1% with 12 iterations makes the output much closer to the requested target. --- packages/image-engine/src/operations/compress.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/image-engine/src/operations/compress.ts b/packages/image-engine/src/operations/compress.ts index bc3b2982..f84f65b4 100644 --- a/packages/image-engine/src/operations/compress.ts +++ b/packages/image-engine/src/operations/compress.ts @@ -58,8 +58,8 @@ async function findBestQuality( let low = 1; let high = 100; let bestQuality: number | null = null; - const maxIterations = 8; - const tolerance = 0.05; + const maxIterations = 12; + const tolerance = 0.01; for (let i = 0; i < maxIterations && low <= high; i++) { const mid = Math.min(100, Math.max(1, Math.round((low + high) / 2)));