]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/image-mode.el (image-transform-fill-window): New command (bug#69565).
authorJuri Linkov <juri@linkov.net>
Tue, 28 May 2024 16:51:21 +0000 (19:51 +0300)
committerEshel Yaron <me@eshelyaron.com>
Wed, 29 May 2024 10:12:15 +0000 (12:12 +0200)
(image-mode-menu): Add image-transform-fill-window to the menu.

(cherry picked from commit 730b61c64b5d86cc3b38ee15d4530fdd2194619b)

lisp/image-mode.el

index fa64f1ac03e13fb770bf2d30bcaa1083ba4003fc..7cf7845e9357ea8c95c5d7861055b299ef02428e 100644 (file)
@@ -559,6 +559,8 @@ image as text, when opening such images in `image-mode'."
      :help "Resize image to match the window height and width"]
     ["Fit Image to Window (Scale down only)" image-transform-fit-both
      :help "Scale image down to match the window height and width"]
+    ["Fill Window with Image" image-transform-fill-window
+     :help "Resize image to fill either width or height of the window"]
     ["Zoom In" image-increase-size
      :help "Enlarge the image"]
     ["Zoom Out" image-decrease-size
@@ -1592,6 +1594,18 @@ The percentage is in relation to the original size of the image."
   (setq image-transform-resize 'fit-window)
   (image-toggle-display-image))
 
+(defun image-transform-fill-window ()
+  "Fill the window with the image while keeping image proportions.
+This means filling the window with the image as much as possible
+without leaving empty space around image edges.  Then you can use
+either horizontal or vertical scrolling to see the remaining parts
+of the image."
+  (interactive nil image-mode)
+  (let ((size (image-display-size (image-get-display-property) t)))
+    (setq image-transform-resize
+          (if (> (car size) (cdr size)) 'fit-height 'fit-width)))
+  (image-toggle-display-image))
+
 (defun image-transform-set-rotation (rotation)
   "Prompt for an angle ROTATION, and rotate the image by that amount.
 ROTATION should be in degrees."