[fractal] Apply EXIF rotation on images loaded with Pixbuf
- From: Daniel Garcia Moreno <danigm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal] Apply EXIF rotation on images loaded with Pixbuf
- Date: Mon, 14 Dec 2020 15:01:07 +0000 (UTC)
commit 41832d4516908ce9c36fde79e7966e14f66141e2
Author: Kévin Commaille <zecakeh pm me>
Date: Fri Dec 11 21:53:47 2020 +0100
Apply EXIF rotation on images loaded with Pixbuf
fractal-gtk/src/actions/message.rs | 5 ++++-
fractal-gtk/src/appop/message.rs | 13 +++++++++----
fractal-gtk/src/widgets/avatar.rs | 8 ++++++--
fractal-gtk/src/widgets/image.rs | 7 +++++--
4 files changed, 24 insertions(+), 9 deletions(-)
---
diff --git a/fractal-gtk/src/actions/message.rs b/fractal-gtk/src/actions/message.rs
index cc63cf04..cf50df71 100644
--- a/fractal-gtk/src/actions/message.rs
+++ b/fractal-gtk/src/actions/message.rs
@@ -184,7 +184,10 @@ pub fn new(
ErrorDialog::new(false, &msg);
}
Ok(Ok(fname)) => {
- if let Ok(pixbuf) = gdk_pixbuf::Pixbuf::from_file(fname) {
+ if let Some(pixbuf) = gdk_pixbuf::Pixbuf::from_file(fname)
+ .ok()
+ .and_then(|pb| pb.apply_embedded_orientation())
+ {
let atom = gdk::Atom::intern("CLIPBOARD");
let clipboard = gtk::Clipboard::get(&atom);
clipboard.set_image(&pixbuf);
diff --git a/fractal-gtk/src/appop/message.rs b/fractal-gtk/src/appop/message.rs
index 460a8fc6..8dc320f3 100644
--- a/fractal-gtk/src/appop/message.rs
+++ b/fractal-gtk/src/appop/message.rs
@@ -563,11 +563,16 @@ fn create_ui_message(
/// and populates the info Json with the information it has
fn get_image_media_info(file: &Path, mimetype: &str) -> Option<JsonValue> {
- let (_, w, h) = Pixbuf::get_file_info(file)?;
+ // We need to load the file to read the orientation in the EXIF data
+ let image = Pixbuf::from_file(&file)
+ .ok()?
+ .apply_embedded_orientation()?;
let size = fs::metadata(file).ok()?.len();
// make thumbnail max 800x600
- let thumb = Pixbuf::from_file_at_scale(&file, 800, 600, true).ok()?;
+ let thumb = Pixbuf::from_file_at_scale(&file, 800, 600, true)
+ .ok()?
+ .apply_embedded_orientation()?;
let mut rng = rand::thread_rng();
let x: u64 = rng.gen_range(1, 9_223_372_036_854_775_807);
let thumb_path = format!(
@@ -587,8 +592,8 @@ fn get_image_media_info(file: &Path, mimetype: &str) -> Option<JsonValue> {
"size": thumb_size,
"mimetype": "image/png"
},
- "w": w,
- "h": h,
+ "w": image.get_width(),
+ "h": image.get_height(),
"size": size,
"mimetype": mimetype,
"orientation": 0
diff --git a/fractal-gtk/src/widgets/avatar.rs b/fractal-gtk/src/widgets/avatar.rs
index 82ed367b..186e7c78 100644
--- a/fractal-gtk/src/widgets/avatar.rs
+++ b/fractal-gtk/src/widgets/avatar.rs
@@ -135,9 +135,13 @@ impl AvatarExt for gtk::Overlay {
fn load_pixbuf(path: &Path, size: i32) -> Option<Pixbuf> {
let (_, width, height) = Pixbuf::get_file_info(&path)?;
let pb = if width > height {
- Pixbuf::from_file_at_scale(&path, -1, size, true).ok()?
+ Pixbuf::from_file_at_scale(&path, -1, size, true)
+ .ok()?
+ .apply_embedded_orientation()?
} else {
- Pixbuf::from_file_at_scale(&path, size, -1, true).ok()?
+ Pixbuf::from_file_at_scale(&path, size, -1, true)
+ .ok()?
+ .apply_embedded_orientation()?
};
Some(pb)
diff --git a/fractal-gtk/src/widgets/image.rs b/fractal-gtk/src/widgets/image.rs
index 760f85e5..c7b0be51 100644
--- a/fractal-gtk/src/widgets/image.rs
+++ b/fractal-gtk/src/widgets/image.rs
@@ -318,8 +318,11 @@ pub fn load_pixbuf(
return;
}
- match Pixbuf::from_file(fname) {
- Ok(px) => {
+ match Pixbuf::from_file(fname)
+ .ok()
+ .and_then(|pb| pb.apply_embedded_orientation())
+ {
+ Some(px) => {
*pix.lock().unwrap() = Some(px);
*scaled.lock().unwrap() = None;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]