diff --git a/src/covers.rs b/src/covers.rs index 1965180..ac147a1 100644 --- a/src/covers.rs +++ b/src/covers.rs @@ -52,17 +52,7 @@ pub fn write_cover( return Err(format!("Invalid cover MIME type: {}", cover.mime_type).into()); } - let path = Path::new(&base_path).join(format!("{hash}.webp")); - - let dynamic_image = image::load_from_memory_with_format( - &cover.bytes, - match cover.mime_type.as_str() { - "image/png" => image::ImageFormat::Png, - "image/jpeg" => image::ImageFormat::Jpeg, - "image/webp" => image::ImageFormat::WebP, - _ => panic!("Invalid cover MIME type (this should never happen)"), - }, - )?; + let dynamic_image = image::load_from_memory(&cover.bytes)?; let resized_image = if dynamic_image.width() > 640 || dynamic_image.height() > 640 { let a = dynamic_image.resize_to_fill(640, 640, image::imageops::FilterType::Lanczos3); @@ -74,6 +64,8 @@ pub fn write_cover( let webp = Encoder::from_image(&resized_image)?.encode_lossless(); + let path = Path::new(&base_path).join(format!("{hash}.webp")); + fs::write(path, webp.as_bytes())?; Ok(())