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:
committed by
Peter Steinberger
parent
7bfc77db25
commit
8c0e290db1
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user