fix(refboard): reuse full image for LOD tiers when source is smaller
Don't re-encode small images to WebP unnecessarily — just return the original buffer for tiers where the source is already smaller than target.
This commit is contained in:
@@ -40,10 +40,8 @@ async function generateLOD(buffer, originalExt) {
|
|||||||
const { maxWidth, quality } = LOD_TIERS[tierKey];
|
const { maxWidth, quality } = LOD_TIERS[tierKey];
|
||||||
|
|
||||||
if (origWidth <= maxWidth) {
|
if (origWidth <= maxWidth) {
|
||||||
// Image is smaller than tier width — convert to WebP but don't upscale
|
// Image is smaller than tier width — reuse full image, no point re-encoding
|
||||||
const result = sharp(buffer).webp({ quality });
|
return full;
|
||||||
const outBuf = await result.toBuffer();
|
|
||||||
return { buffer: outBuf, ext: '.webp', width: origWidth, height: origHeight };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resize down (width-based, preserve aspect ratio)
|
// Resize down (width-based, preserve aspect ratio)
|
||||||
|
|||||||
Reference in New Issue
Block a user