use std::io::Cursor; /// Transcode arbitrary cover image bytes (PNG, WebP, GIF, BMP, JPEG, ...) to /// JPEG so the stored `cover.jpg` is always a real JPEG. Returns `None` if the /// bytes can't be decoded. CPU-bound — call from `spawn_blocking`. pub fn to_jpeg(bytes: &[u8]) -> Option> { let img = image::load_from_memory(bytes).ok()?; let mut out = Cursor::new(Vec::new()); image::DynamicImage::ImageRgb8(img.to_rgb8()) .write_to(&mut out, image::ImageFormat::Jpeg) .ok()?; Some(out.into_inner()) }