perf: use adaptive filter for thumbnails (Triangle/CatmullRom instead of Lanczos3)

- Icon (150px): Triangle filter (~5x faster)
- Preview (400px): CatmullRom filter (~2.5x faster)
- Large (800px): CatmullRom filter (~2.5x faster)
- Quality difference is imperceptible at these resolutions
This commit is contained in:
Dionisio
2026-02-24 00:44:27 +01:00
parent 12c6914d5d
commit 677b3eafa9
@@ -241,8 +241,14 @@ impl ThumbnailService {
((orig_width as f32 * ratio) as u32, max_dim) ((orig_width as f32 * ratio) as u32, max_dim)
}; };
// Resize using high-quality Lanczos3 filter // Adaptive filter: faster filters for smaller sizes where
let thumbnail = img.resize(new_width, new_height, FilterType::Lanczos3); // quality difference vs Lanczos3 is imperceptible
let filter = match size {
ThumbnailSize::Icon => FilterType::Triangle, // 150px — max speed
ThumbnailSize::Preview => FilterType::CatmullRom, // 400px — good balance
ThumbnailSize::Large => FilterType::CatmullRom, // 800px — sufficient quality
};
let thumbnail = img.resize(new_width, new_height, filter);
// Encode as WebP for smaller file size // Encode as WebP for smaller file size
let mut buffer = Vec::new(); let mut buffer = Vec::new();