mirror of
https://github.com/getzola/zola
synced 2024-11-10 06:14:19 +00:00
Fix resizing for images with EXIF orientation (#2468)
* Fix resizing for images with EXIF orientation * Added test for asymmetric resize for exif images --------- Co-authored-by: Tanishq <tanishq@levels.fyi>
This commit is contained in:
parent
954f1ce533
commit
6a25b62d43
2 changed files with 24 additions and 3 deletions
|
@ -38,7 +38,8 @@ impl ImageOp {
|
|||
return Ok(());
|
||||
}
|
||||
|
||||
let mut img = image::open(&self.input_path)?;
|
||||
let img = image::open(&self.input_path)?;
|
||||
let mut img = fix_orientation(&img, &self.input_path).unwrap_or(img);
|
||||
|
||||
let img = match self.instr.crop_instruction {
|
||||
Some((x, y, w, h)) => img.crop(x, y, w, h),
|
||||
|
@ -49,8 +50,6 @@ impl ImageOp {
|
|||
None => img,
|
||||
};
|
||||
|
||||
let img = fix_orientation(&img, &self.input_path).unwrap_or(img);
|
||||
|
||||
let f = File::create(&self.output_path)?;
|
||||
let mut buffered_f = BufWriter::new(f);
|
||||
|
||||
|
|
|
@ -248,3 +248,25 @@ fn check_img(img: DynamicImage) -> bool {
|
|||
// bottom right is white
|
||||
&& img.get_pixel(15, 15).channels() == [255, 255, 255, 255]
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn asymmetric_resize_with_exif_orientations() {
|
||||
// No exif metadata
|
||||
image_op_test("exif_0.jpg", "scale", Some(16), Some(32), "auto", "jpg", 16, 32, 16, 16);
|
||||
// 1: Horizontal (normal)
|
||||
image_op_test("exif_1.jpg", "scale", Some(16), Some(32), "auto", "jpg", 16, 32, 16, 16);
|
||||
// 2: Mirror horizontal
|
||||
image_op_test("exif_2.jpg", "scale", Some(16), Some(32), "auto", "jpg", 16, 32, 16, 16);
|
||||
// 3: Rotate 180
|
||||
image_op_test("exif_3.jpg", "scale", Some(16), Some(32), "auto", "jpg", 16, 32, 16, 16);
|
||||
// 4: Mirror vertical
|
||||
image_op_test("exif_4.jpg", "scale", Some(16), Some(32), "auto", "jpg", 16, 32, 16, 16);
|
||||
// 5: Mirror horizontal and rotate 270 CW
|
||||
image_op_test("exif_5.jpg", "scale", Some(16), Some(32), "auto", "jpg", 16, 32, 16, 16);
|
||||
// 6: Rotate 90 CW
|
||||
image_op_test("exif_6.jpg", "scale", Some(16), Some(32), "auto", "jpg", 16, 32, 16, 16);
|
||||
// 7: Mirror horizontal and rotate 90 CW
|
||||
image_op_test("exif_7.jpg", "scale", Some(16), Some(32), "auto", "jpg", 16, 32, 16, 16);
|
||||
// 8: Rotate 270 CW
|
||||
image_op_test("exif_8.jpg", "scale", Some(16), Some(32), "auto", "jpg", 16, 32, 16, 16);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue