From e57c1c9322bf0620514838e7203a87eef657a13b Mon Sep 17 00:00:00 2001 From: electria Date: Sat, 1 Aug 2026 10:22:41 -0700 Subject: [PATCH] fix: jxls being rotated twice --- src/utils.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/utils.rs b/src/utils.rs index 474c3b3..ae1dbb1 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,5 +1,6 @@ use std::{ borrow::Cow, + ffi::OsStr, path::{Path, PathBuf}, }; @@ -11,7 +12,7 @@ pub fn load_image(path: impl AsRef) -> Result { load_image_impl(path).map_err(|e| e.to_string()) } fn load_image_impl(path: impl AsRef) -> ImageResult { - let mut decoder = ImageReader::open(path)? + let mut decoder = ImageReader::open(&path)? .with_guessed_format()? .into_decoder()?; @@ -19,7 +20,17 @@ fn load_image_impl(path: impl AsRef) -> ImageResult { let mut decoded_image = DynamicImage::from_decoder(decoder)?; - decoded_image.apply_orientation(oreintation); + // the condition is a workaround to not rotate JXL images twice; + // since they are already rotated by the decoder + // (while jpegs for instance aren't) + if !path + .as_ref() + .extension() + .map(OsStr::to_string_lossy) + .is_some_and(|s| s == "jxl") + { + decoded_image.apply_orientation(oreintation); + } Ok(decoded_image.into_rgba8()) }