From 0bcc18c637ed98ddd1662b9484f0137db8594ec7 Mon Sep 17 00:00:00 2001 From: Matt Fellenz Date: Sun, 14 Jun 2026 00:39:24 +0200 Subject: [PATCH] Respect `image`'s orientation --- crates/egui_extras/src/image.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/egui_extras/src/image.rs b/crates/egui_extras/src/image.rs index b5ed70fa1fde..e861d9332663 100644 --- a/crates/egui_extras/src/image.rs +++ b/crates/egui_extras/src/image.rs @@ -12,8 +12,23 @@ use egui::SizeHint; /// On invalid image or unsupported image format. #[cfg(feature = "image")] pub fn load_image_bytes(image_bytes: &[u8]) -> Result { + fn load_image_with_orientation(image_bytes: &[u8]) -> image::ImageResult { + use std::io::Cursor; + + use image::{DynamicImage, ImageDecoder, ImageReader}; + + let format = image::guess_format(image_bytes)?; + let reader = Cursor::new(image_bytes); + let reader = ImageReader::with_format(reader, format); + let mut decoder = reader.into_decoder()?; + let orientation = ImageDecoder::orientation(&mut decoder)?; + let mut image = DynamicImage::from_decoder(decoder)?; + image.apply_orientation(orientation); + Ok(image) + } + profiling::function_scope!(); - let image = image::load_from_memory(image_bytes).map_err(|err| match err { + let image = load_image_with_orientation(image_bytes).map_err(|err| match err { image::ImageError::Unsupported(err) => match err.kind() { image::error::UnsupportedErrorKind::Format(format) => { egui::load::LoadError::FormatNotSupported {