Save edited images as PNG by default to prevent JPEG compression buildup
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 <noreply@anthropic.com>
This commit is contained in:
+6
-2
@@ -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',
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user