From 198de74b1e1663da07f38e86ebfb56915df59a02 Mon Sep 17 00:00:00 2001 From: Francis De Brabandere Date: Thu, 9 May 2024 20:08:10 +0200 Subject: [PATCH] fix(extracted): unknown image extension --- src/vpx/expanded.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/vpx/expanded.rs b/src/vpx/expanded.rs index 93be41b..b5dfd0e 100644 --- a/src/vpx/expanded.rs +++ b/src/vpx/expanded.rs @@ -272,7 +272,7 @@ fn write_images>(vpx: &VPX, expanded_dir: &P) -> Result<(), Write if let Some(jpeg) = &image.jpeg { // Only if the actual image dimensions are different from // the ones in the vpx file we add them to the json. - let dimensions_file = read_image_dimensions_from_file_steam(&file_name, jpeg)?; + let dimensions_file = read_image_dimensions_from_file_steam(&file_name, jpeg); match dimensions_file { Some((width_file, height_file)) => { if image.width != width_file { @@ -527,16 +527,17 @@ fn read_image_dimensions(file_path: &PathBuf) -> io::Result> fn read_image_dimensions_from_file_steam( file_name: &String, jpeg: &ImageDataJpeg, -) -> io::Result> { - let format = image::ImageFormat::from_path(file_name).map_err(|e| { - io::Error::new( - io::ErrorKind::InvalidData, - format!("Failed to determine image format for {}: {}", file_name, e), - ) - })?; +) -> Option<(u32, u32)> { + let format = match image::ImageFormat::from_path(file_name) { + Ok(format) => Some(format), + Err(e) => { + eprintln!("Failed to determine image format for {}: {}", file_name, e); + None + } + }?; let cursor = std::io::Cursor::new(&jpeg.data); let decoder = image::io::Reader::with_format(cursor, format); - let dimensions_file = match decoder.into_dimensions() { + match decoder.into_dimensions() { Ok(dimensions) => Some(dimensions), Err(image_error) => { eprintln!( @@ -545,8 +546,7 @@ fn read_image_dimensions_from_file_steam( ); None } - }; - Ok(dimensions_file) + } } struct ImageBmp {