fix: jxls being rotated twice
This commit is contained in:
parent
d3bc84769e
commit
e57c1c9322
1 changed files with 13 additions and 2 deletions
13
src/utils.rs
13
src/utils.rs
|
|
@ -1,5 +1,6 @@
|
||||||
use std::{
|
use std::{
|
||||||
borrow::Cow,
|
borrow::Cow,
|
||||||
|
ffi::OsStr,
|
||||||
path::{Path, PathBuf},
|
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())
|
load_image_impl(path).map_err(|e| e.to_string())
|
||||||
}
|
}
|
||||||
fn load_image_impl(path: impl AsRef<Path>) -> ImageResult<RgbaImage> {
|
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()?
|
.with_guessed_format()?
|
||||||
.into_decoder()?;
|
.into_decoder()?;
|
||||||
|
|
||||||
|
|
@ -19,7 +20,17 @@ fn load_image_impl(path: impl AsRef<Path>) -> ImageResult<RgbaImage> {
|
||||||
|
|
||||||
let mut decoded_image = DynamicImage::from_decoder(decoder)?;
|
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);
|
decoded_image.apply_orientation(oreintation);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(decoded_image.into_rgba8())
|
Ok(decoded_image.into_rgba8())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue