fix: jxls being rotated twice

This commit is contained in:
electria 2026-08-01 10:22:41 -07:00
commit e57c1c9322
Signed by: electria
SSH key fingerprint: SHA256:8LlB3ucPbBHqozqkhsNbaV5oG3SlzzqUj8FZDL6IPQs

View file

@ -1,5 +1,6 @@
use std::{
borrow::Cow,
ffi::OsStr,
path::{Path, PathBuf},
};
@ -11,7 +12,7 @@ pub fn load_image(path: impl AsRef<Path>) -> Result<RgbaImage, String> {
load_image_impl(path).map_err(|e| e.to_string())
}
fn load_image_impl(path: impl AsRef<Path>) -> ImageResult<RgbaImage> {
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<Path>) -> ImageResult<RgbaImage> {
let mut decoded_image = DynamicImage::from_decoder(decoder)?;
// 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())
}