fix: enhance image reference detection and optimize image processing

- Added support for detecting file URLs in prompts using fileURLToPath for accurate path resolution.
- Updated image loading logic to default to JPEG format for optimized image processing.
- Improved error handling in image optimization to continue processing on failures.
This commit is contained in:
Tyler Yust
2026-01-17 03:24:34 -08:00
committed by Peter Steinberger
parent 7bfc77db25
commit 8c0e290db1
2 changed files with 37 additions and 19 deletions

View File

@@ -161,23 +161,27 @@ export async function optimizeImageToJpeg(
for (const side of sides) {
for (const quality of qualities) {
const out = await resizeToJpeg({
buffer,
maxSide: side,
quality,
withoutEnlargement: true,
});
const size = out.length;
if (!smallest || size < smallest.size) {
smallest = { buffer: out, size, resizeSide: side, quality };
}
if (size <= maxBytes) {
return {
buffer: out,
optimizedSize: size,
resizeSide: side,
try {
const out = await resizeToJpeg({
buffer,
maxSide: side,
quality,
};
withoutEnlargement: true,
});
const size = out.length;
if (!smallest || size < smallest.size) {
smallest = { buffer: out, size, resizeSide: side, quality };
}
if (size <= maxBytes) {
return {
buffer: out,
optimizedSize: size,
resizeSide: side,
quality,
};
}
} catch {
// Continue trying other size/quality combinations
}
}
}