Optimize thumbnail workers and adaptive indexing

This commit is contained in:
2026-04-05 20:36:11 +01:00
parent 8b391059ba
commit 76ec424167
7 changed files with 471 additions and 113 deletions
+6 -3
View File
@@ -2,8 +2,8 @@ use crate::media::MediaTools;
use anyhow::{anyhow, Result};
use fast_image_resize as fir;
use fast_image_resize::IntoImageView;
use image::codecs::jpeg::JpegEncoder;
use image::ImageDecoder;
use image::ImageFormat;
use std::path::{Path, PathBuf};
pub const THUMB_SIZE: u32 = 320;
@@ -53,7 +53,10 @@ pub fn generate_image_thumbnail(image_path: &Path, cache_dir: &Path) -> Result<G
std::fs::create_dir_all(parent)?;
}
image::DynamicImage::ImageRgba8(thumb).save_with_format(&out_path, ImageFormat::WebP)?;
let thumb = image::DynamicImage::ImageRgba8(thumb).into_rgb8();
let mut output_file = std::fs::File::create(&out_path)?;
let mut encoder = JpegEncoder::new_with_quality(&mut output_file, 82);
encoder.encode_image(&thumb)?;
Ok(GeneratedThumbnail {
path: out_path,
width: original_dimensions.0,
@@ -146,7 +149,7 @@ pub fn generate_video_thumbnail(
}
pub fn thumb_path(cache_dir: &Path, image_path: &str) -> PathBuf {
thumb_path_with_ext(cache_dir, image_path, "webp")
thumb_path_with_ext(cache_dir, image_path, "jpg")
}
pub fn video_poster_path(cache_dir: &Path, video_path: &str) -> PathBuf {