From 4f536861bbf29b3b48f6c139b277c4825cc67505 Mon Sep 17 00:00:00 2001 From: kim Date: Mon, 18 May 2026 23:09:01 +0900 Subject: [PATCH] Save edited images as PNG by default to prevent JPEG compression buildup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When no explicit output path is given and source is JPEG/WebP, output defaults to PNG (lossless). This avoids cumulative quality loss on repeated edits (brightness → contrast → filter → ...). Exception: 'convert' operation keeps the original format so explicit format-change requests still work. Explicit output path always honored. Also fix quality default mismatch: TS params was 85, Python was 92. Now both are 92 for when JPEG/WebP output is explicitly requested. Co-Authored-By: Claude Sonnet 4.6 --- src/tools/image.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/tools/image.ts b/src/tools/image.ts index 4b15dac..d343d1b 100644 --- a/src/tools/image.ts +++ b/src/tools/image.ts @@ -692,11 +692,15 @@ export const imageEditTool = { if (!fs.existsSync(resolved)) return { success: false, error: `File not found: ${resolved}` }; // determine output path + // Default to PNG for lossy source formats to avoid cumulative compression loss. + // Only exception: 'convert' operation (user explicitly wants a format change). let outPath = String(args?.output || '').trim(); if (!outPath) { + const origExt = path.extname(resolved).toLowerCase(); + const lossyFmts = new Set(['.jpg', '.jpeg', '.webp']); const ext = args?.format ? `.${args.format}` - : (operation === 'convert' ? '.png' : path.extname(resolved)); + : (operation === 'convert' ? origExt : (lossyFmts.has(origExt) ? '.png' : origExt)); const base = path.basename(resolved, path.extname(resolved)); outPath = path.join(path.dirname(resolved), `${base}_${operation}_${Date.now()}${ext}`); } else if (!path.isAbsolute(outPath)) { @@ -718,7 +722,7 @@ export const imageEditTool = { text: args?.text ?? '', position: args?.position ?? 'bottom-right', opacity: args?.opacity ?? 0.5, - quality: args?.quality ?? 85, + quality: args?.quality ?? 92, style: args?.style ?? 'painting', };