unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#41886: 27.1; Rotated image doesn't fit to window height
@ 2020-06-15 23:27 Juri Linkov
  2020-06-16 14:46 ` Eli Zaretskii
  0 siblings, 1 reply; 2+ messages in thread
From: Juri Linkov @ 2020-06-15 23:27 UTC (permalink / raw)
  To: 41886

[-- Attachment #1: Type: text/plain, Size: 386 bytes --]

Version: 27.1
Tags: patch

I found a bug in image-mode on emacs-27.

Using the default value 't' of 'image-transform-resize'
(that means to fit the image to the window height and width),
when an image has exif-orientation 90 and visited in image-mode,
it's rotated, but doesn't fit to the window height,
only the upper half of the image is displayed.
The patch that fixes this problem:

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: image-mode-fit-rotated-image.patch --]
[-- Type: text/x-diff, Size: 1676 bytes --]

diff --git a/lisp/image-mode.el b/lisp/image-mode.el
index b82c066918..019f6e20ce 100644
--- a/lisp/image-mode.el
+++ b/lisp/image-mode.el
@@ -810,8 +810,12 @@ image-toggle-display-image
 	    filename))
 	 ;; If we have a `fit-width' or a `fit-height', don't limit
 	 ;; the size of the image to the window size.
-	 (edges (and (eq image-transform-resize t)
-		     (window-inside-pixel-edges (get-buffer-window))))
+	 (edges (when (eq image-transform-resize t)
+		  (window-inside-pixel-edges (get-buffer-window))))
+	 (max-width (when edges
+		      (- (nth 2 edges) (nth 0 edges))))
+	 (max-height (when edges
+		       (- (nth 3 edges) (nth 1 edges))))
 	 (type (if (image--imagemagick-wanted-p filename)
 		   'imagemagick
 		 (image-type file-or-data nil data-p)))
@@ -827,14 +831,18 @@ image-toggle-display-image
                  (ignore-error exif-error
                    (exif-parse-buffer)))
                 0.0)))
+    ;; Swap width and height when changing orientation
+    ;; between portrait and landscape.
+    (when (and edges (memq (truncate image-transform-rotation) '(90 270)))
+      (setq max-width (prog1 max-height (setq max-height max-width))))
 
     ;; :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)))))
+				:max-width max-width
+				:max-height max-height)))
 
     ;; Discard any stale image data before looking it up again.
     (image-flush image)

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* bug#41886: 27.1; Rotated image doesn't fit to window height
  2020-06-15 23:27 bug#41886: 27.1; Rotated image doesn't fit to window height Juri Linkov
@ 2020-06-16 14:46 ` Eli Zaretskii
  0 siblings, 0 replies; 2+ messages in thread
From: Eli Zaretskii @ 2020-06-16 14:46 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 41886

> From: Juri Linkov <juri@linkov.net>
> Date: Tue, 16 Jun 2020 02:27:31 +0300
> 
> I found a bug in image-mode on emacs-27.
> 
> Using the default value 't' of 'image-transform-resize'
> (that means to fit the image to the window height and width),
> when an image has exif-orientation 90 and visited in image-mode,
> it's rotated, but doesn't fit to the window height,
> only the upper half of the image is displayed.
> The patch that fixes this problem:

Thanks, this is okay for the release branch.





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-06-16 14:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-15 23:27 bug#41886: 27.1; Rotated image doesn't fit to window height Juri Linkov
2020-06-16 14:46 ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).