Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix resizing for images with EXIF orientation #2468

Merged
merged 2 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions components/imageproc/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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);

Expand Down
22 changes: 22 additions & 0 deletions components/imageproc/tests/resize_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}