[Bug]: little exif throws errors when image has no metadata
Is there an existing issue for this?
- [x] I have searched the existing issues
Description
When input image doesn't have metadata - error message is shown
Expected behavior
No error in the console
Library Version
0.11.0 (latest)
Steps To Reproduce
No response
Anything else?
No response
Based on this comment https://github.com/SalOne22/rimage/issues/314#issuecomment-3168190144
https://github.com/SalOne22/rimage/issues/314#issuecomment-3168190144 It has already demonstrated issues with the PNG format, and now a similar problem seems to be occurring with the WEBP format, where the WEBP format is not being successfully converted. I tested versions 0.11.0 and 0.12.1, and version 0.11.0 was able to perform the conversion normally.
D:\0\test0_11_0>rimage.exe --version
rimage 0.11.0
D:\0\test0_11_0>rimage.exe mozjpeg --quality 90 --quantization 100 --dithering 100 *.webp
File Size
IMG_0001.jpg 222.51 kB > 334.11 kB 50.15%
IMG_0015.jpg 193.81 kB > 291.93 kB 50.63%
IMG_0010.jpg 186.57 kB > 290.65 kB 55.79%
IMG_0008.jpg 189.86 kB > 286.17 kB 50.73%
IMG_0003.jpg 181.24 kB > 282.51 kB 55.88%
IMG_0002.jpg 179.00 kB > 276.88 kB 54.68%
IMG_0009.jpg 180.29 kB > 275.31 kB 52.70%
IMG_0005.jpg 167.30 kB > 267.66 kB 59.99%
IMG_0007.jpg 162.36 kB > 258.24 kB 59.06%
IMG_0013.jpg 164.58 kB > 255.55 kB 55.27%
IMG_0014.jpg 153.38 kB > 250.92 kB 63.60%
IMG_0006.jpg 154.40 kB > 245.72 kB 59.15%
IMG_0012.jpg 152.78 kB > 245.14 kB 60.46%
IMG_0004.jpg 146.19 kB > 237.84 kB 62.69%
IMG_0011.jpg 132.66 kB > 220.14 kB 65.95%
IMG_0016.jpg 120.19 kB > 202.68 kB 68.64%
Total: 2.69 MB > 4.22 MB 57.10%`
`D:\0\test0_12_1>rimage.exe --version
rimage 0.12.1
D:\0\test0_12_1>rimage.exe mozjpeg --quality 90 --quantization 100 --dithering 100 *.webp
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 16/16
⠁ IMG_0013.webp
⠁ IMG_0015.webp
⠁ IMG_0008.webp
⠁ IMG_0003.webp
⠁ IMG_0005.webp
⠁ IMG_0016.webp
⠁ IMG_0011.webp
⠁ IMG_0009.webp
⠁ IMG_0001.webp
thread '<unnamed>' panicked at C:\Users\runneradmin\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\little_exif-0.6.14\src\webp\file.rs:269:66:
called `Result::unwrap()` on an `Err` value: Custom { kind: Other, error: "Expected first chunk of WebP file to be of type 'VP8X' but instead got VP8 !" }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
After testing, I've found that little_exif ONLY support jpg and jpeg. Png, moz, webp, etc format would make it panic or Failed and sometimes WITHOUT any tip.
use little_exif::{exif_tag::ExifTag, ifd::ExifTagGroup, metadata::Metadata as ExifMetadata};
use std::path::PathBuf;
fn main() {
let input = PathBuf::from(r"D:\read.png");
let w = 5120;
let h = 2880;
let output = PathBuf::from(r"D:\write.webp"); // create pics with format and change it manutally
//std::fs::remove_file(&output).ok();
//std::fs::copy(&input, &output).ok();
let mut exif_metadata = match ExifMetadata::new_from_path(&input) {
Ok(metadata) => {
println!("?Ok");
metadata
}
Err(_) => {
println!("?Err");
ExifMetadata::new()
}
};
println!("?B{:?}", exif_metadata.get_ifds());
exif_metadata
.get_ifd_mut(ExifTagGroup::GENERIC, 0)
.set_tag(ExifTag::ExifImageWidth(vec![w as u32]));
exif_metadata
.get_ifd_mut(ExifTagGroup::GENERIC, 0)
.set_tag(ExifTag::ExifImageHeight(vec![h as u32]));
exif_metadata
.get_ifd_mut(ExifTagGroup::GENERIC, 0)
.set_tag(ExifTag::ImageWidth(vec![w as u32]));
exif_metadata
.get_ifd_mut(ExifTagGroup::GENERIC, 0)
.set_tag(ExifTag::ImageHeight(vec![h as u32]));
exif_metadata
.get_ifd_mut(ExifTagGroup::GENERIC, 0)
.set_tag(ExifTag::ImageDescription("asdf".to_string()));
println!("?O{:?}", exif_metadata.get_ifds());
//exif_metadata.reduce_to_a_minimum();
//println!("?S{:?}", exif_metadata.get_ifds());
match exif_metadata.write_to_file(&output) {
Ok(_) => (),
Err(_) => println!("!!!"),
}
}