Merge pull request #64 from alexwlchan/handle-exif-orientation
- ID
de9b9c6- date
2025-09-08 12:57:32+00:00- author
Alex Chan <alex@alexwlchan.net>- parents
e42608a,06383d1- message
Merge pull request #64 from alexwlchan/handle-exif-orientation Handle images with EXIF orientation properly- changed files
6 files, 38 additions, 3 deletions
Changed files
CHANGELOG.md (207) → CHANGELOG.md (348)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d5ccecf..c20333e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog
+## v1.0.2 - 2025-09-08
+
+Pay attention to EXIF orientation in input images, so thumbnails have the same rotation/reflection as the original.
+
## v1.0.1 - 2024-08-20
Fix a bug where the tool couldn't create thumbnails of animated GIFs if the thumbnail would have an odd width/height dimension.
CONTRIBUTING.md (0) → CONTRIBUTING.md (355)
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..be23ab5
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,11 @@
+# CONTRIBUTING
+
+## Releasing a new version
+
+1. Bump the version number in `Cargo.toml`
+2. Create a new changelog entry for your version in `CHANGELOG.md`
+3. Commit your change
+4. Create a Git tag with your version number
+5. Push your new commit and Git tag to GitHub
+
+GitHub Actions will then build and release a new version of the CLI tool for you.
Cargo.lock (39009) → Cargo.lock (39009)
diff --git a/Cargo.lock b/Cargo.lock
index b692122..59506b1 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -301,7 +301,7 @@ dependencies = [
[[package]]
name = "create_thumbnail"
-version = "1.0.1"
+version = "1.0.2"
dependencies = [
"assert_cmd",
"clap",
Cargo.toml (206) → Cargo.toml (206)
diff --git a/Cargo.toml b/Cargo.toml
index a27b09d..4972d4d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "create_thumbnail"
-version = "1.0.1"
+version = "1.0.2"
edition = "2021"
[dependencies]
src/create_thumbnail.rs (7988) → src/create_thumbnail.rs (8839)
diff --git a/src/create_thumbnail.rs b/src/create_thumbnail.rs
index 4ca09e6..439182a 100644
--- a/src/create_thumbnail.rs
+++ b/src/create_thumbnail.rs
@@ -3,6 +3,7 @@ use std::process::Command;
use std::str;
use image::imageops::FilterType;
+use image::{DynamicImage, ImageDecoder, ImageReader};
use crate::create_parent_directory::create_parent_directory;
use crate::errors::ThumbnailError;
@@ -143,6 +144,22 @@ mod test_create_thumbnail {
assert!(thumbnail_path.exists());
assert_eq!(get_dimensions(&thumbnail_path), (128, 256));
}
+
+ #[test]
+ fn it_applies_exif_orientation() {
+ // This source image comes from Dave Perrett's exif-orientation-examples
+ // repo, and is used under MIT.
+ // See https://github.com/recurser/exif-orientation-examples
+ let img_path = PathBuf::from("src/tests/Landscape_5.jpg");
+ let out_dir = test_dir();
+ let target = TargetDimension::MaxWidth(180);
+
+ let thumbnail_path = create_thumbnail(&img_path, &out_dir, target).unwrap();
+
+ assert_eq!(thumbnail_path, out_dir.join("Landscape_5.jpg"));
+ assert!(thumbnail_path.exists());
+ assert_eq!(get_dimensions(&thumbnail_path), (180, 120));
+ }
}
/// Return this value if it's even, or the closest value which is even.
@@ -233,7 +250,10 @@ pub fn create_static_thumbnail(
let thumbnail_path = out_dir.join(file_name);
- let img = image::open(image_path).map_err(ThumbnailError::ImageOpenError)?;
+ let mut decoder = ImageReader::open(image_path)?.into_decoder()?;
+ let orientation = decoder.orientation()?;
+ let mut img = DynamicImage::from_decoder(decoder)?;
+ img.apply_orientation(orientation);
img.resize(width, height, FilterType::Lanczos3)
.save(&thumbnail_path)
src/tests/Landscape_5.jpg (0) → src/tests/Landscape_5.jpg (351275)
diff --git a/src/tests/Landscape_5.jpg b/src/tests/Landscape_5.jpg
new file mode 100644
index 0000000..975d858
Binary files /dev/null and b/src/tests/Landscape_5.jpg differ