aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Ingebrigtsen2019-09-22 14:21:39 +0200
committerLars Ingebrigtsen2019-09-22 14:21:47 +0200
commit8542f666023931f85817f590926cc3e9bc992b68 (patch)
tree25779c3d5277d6d587223ef36cd75cdfb5b10fbd
parent0c9a9d4219f2ada2b12cff4476a9d27bab40a862 (diff)
downloademacs-8542f666023931f85817f590926cc3e9bc992b68.tar.gz
emacs-8542f666023931f85817f590926cc3e9bc992b68.zip
Automatically rotate images in image-mode based on Exif data
* lisp/image-mode.el (image-toggle-display-image): Get the orientation from the Exif data, if any.
-rw-r--r--lisp/image-mode.el23
1 files changed, 16 insertions, 7 deletions
diff --git a/lisp/image-mode.el b/lisp/image-mode.el
index fae928f4e67..aaec9026e57 100644
--- a/lisp/image-mode.el
+++ b/lisp/image-mode.el
@@ -39,6 +39,7 @@
39;;; Code: 39;;; Code:
40 40
41(require 'image) 41(require 'image)
42(require 'exif)
42(eval-when-compile (require 'cl-lib)) 43(eval-when-compile (require 'cl-lib))
43 44
44;;; Image mode window-info management. 45;;; Image mode window-info management.
@@ -744,17 +745,25 @@ was inserted."
744 (type (if (image--imagemagick-wanted-p filename) 745 (type (if (image--imagemagick-wanted-p filename)
745 'imagemagick 746 'imagemagick
746 (image-type file-or-data nil data-p))) 747 (image-type file-or-data nil data-p)))
747 ;; :scale 1: If we do not set this, create-image will apply 748 (inhibit-read-only t)
748 ;; default scaling based on font size. 749 (buffer-undo-list t)
749 (image (if (not edges) 750 (modified (buffer-modified-p))
751 props image)
752
753 ;; Get the rotation data from the file, if any.
754 (setq image-transform-rotation
755 (or (exif-orientation
756 (ignore-error exif-error
757 (exif-parse-buffer)))
758 0.0))
759
760 ;; :scale 1: If we do not set this, create-image will apply
761 ;; default scaling based on font size.
762 (setq image (if (not edges)
750 (create-image file-or-data type data-p :scale 1) 763 (create-image file-or-data type data-p :scale 1)
751 (create-image file-or-data type data-p :scale 1 764 (create-image file-or-data type data-p :scale 1
752 :max-width (- (nth 2 edges) (nth 0 edges)) 765 :max-width (- (nth 2 edges) (nth 0 edges))
753 :max-height (- (nth 3 edges) (nth 1 edges))))) 766 :max-height (- (nth 3 edges) (nth 1 edges)))))
754 (inhibit-read-only t)
755 (buffer-undo-list t)
756 (modified (buffer-modified-p))
757 props)
758 767
759 ;; Discard any stale image data before looking it up again. 768 ;; Discard any stale image data before looking it up again.
760 (image-flush image) 769 (image-flush image)