From 7c01d37556a992cba17889119dc68ac9e1f94926 Mon Sep 17 00:00:00 2001 From: TTtie Date: Tue, 25 Aug 2026 14:28:20 +0000 Subject: [PATCH] Prefer full-res image if the full-res image is smaller --- src/compress.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/compress.rs b/src/compress.rs index cdabfd7..c1813d0 100644 --- a/src/compress.rs +++ b/src/compress.rs @@ -52,10 +52,18 @@ pub fn encode_outputs(img: &RgbaImage, crop: Crop, enc: &Encoding) -> Result<(Ve h: main.height() as usize, }; let thumb = resize_to_fit(&main, full, MAX_THUMB_WIDTH, MAX_THUMB_HEIGHT); - let thumb_png = encode_png( - thumb.as_ref().unwrap_or(&main), - enc.colors.map(|c| c.min(THUMB_COLORS)), - )?; + let thumb_png = { + let actual_thumb = encode_png( + thumb.as_ref().unwrap_or(&main), + enc.colors.map(|c| c.min(THUMB_COLORS)), + )?; + // Prefer full-res image if the thumbnail ends up larger than the main image + if actual_thumb.len() > main_png.len() { + main_png.clone() + } else { + actual_thumb + } + }; Ok((main_png, thumb_png)) }