diff options
author | Lars Ingebrigtsen <larsi@gnus.org> | 2019-09-22 14:21:39 +0200 |
---|---|---|
committer | Lars Ingebrigtsen <larsi@gnus.org> | 2019-09-22 14:21:47 +0200 |
commit | 8542f666023931f85817f590926cc3e9bc992b68 (patch) | |
tree | 25779c3d5277d6d587223ef36cd75cdfb5b10fbd /lisp/image-mode.el | |
parent | 0c9a9d4219f2ada2b12cff4476a9d27bab40a862 (diff) | |
download | emacs-8542f666023931f85817f590926cc3e9bc992b68.tar.gz emacs-8542f666023931f85817f590926cc3e9bc992b68.tar.bz2 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.
Diffstat (limited to 'lisp/image-mode.el')
-rw-r--r-- | lisp/image-mode.el | 23 |
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 @@ ;;; Code: (require 'image) +(require 'exif) (eval-when-compile (require 'cl-lib)) ;;; Image mode window-info management. @@ -744,17 +745,25 @@ was inserted." (type (if (image--imagemagick-wanted-p filename) 'imagemagick (image-type file-or-data nil data-p))) - ;; :scale 1: If we do not set this, create-image will apply - ;; default scaling based on font size. - (image (if (not edges) + (inhibit-read-only t) + (buffer-undo-list t) + (modified (buffer-modified-p)) + props image) + + ;; Get the rotation data from the file, if any. + (setq image-transform-rotation + (or (exif-orientation + (ignore-error exif-error + (exif-parse-buffer))) + 0.0)) + + ;; :scale 1: If we do not set this, create-image will apply + ;; default scaling based on font size. + (setq image (if (not edges) (create-image file-or-data type data-p :scale 1) (create-image file-or-data type data-p :scale 1 :max-width (- (nth 2 edges) (nth 0 edges)) :max-height (- (nth 3 edges) (nth 1 edges))))) - (inhibit-read-only t) - (buffer-undo-list t) - (modified (buffer-modified-p)) - props) ;; Discard any stale image data before looking it up again. (image-flush image) |