]> git.eshelyaron.com Git - emacs.git/commitdiff
Scale images in iimage-mode
authorLars Ingebrigtsen <larsi@gnus.org>
Sun, 28 Jul 2019 14:48:15 +0000 (16:48 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Sun, 28 Jul 2019 14:48:20 +0000 (16:48 +0200)
* lisp/iimage.el (iimage-mode-buffer): Scale images down to the
width/height of the buffer (bug#23434).  Also add `image-map' to
the images so that they can be further scaled.

lisp/iimage.el

index 39ee1fb805c12fb6edbd9fc3c0a0123505a8ce56..3b5006491aaabfeb4b07cbe07fb60c37f3cc4f8d 100644 (file)
@@ -116,6 +116,7 @@ Examples of image filename patterns to match:
 (defun iimage-mode-buffer (arg)
   "Display images if ARG is non-nil, undisplay them otherwise."
   (let ((image-path (cons default-directory iimage-mode-image-search-path))
+        (edges (window-inside-pixel-edges (get-buffer-window)))
        file)
     (with-silent-modifications
       (save-excursion
@@ -128,10 +129,15 @@ Examples of image filename patterns to match:
               ;; remove them either (we may leave some of ours, and we
               ;; may remove other packages's display properties).
               (if arg
-                  (add-text-properties (match-beginning 0) (match-end 0)
-                                       `(display ,(create-image file)
-                                         modification-hooks
-                                         (iimage-modification-hook)))
+                  (add-text-properties
+                   (match-beginning 0) (match-end 0)
+                   `(display
+                     ,(create-image file nil nil
+                                    :max-width (- (nth 2 edges) (nth 0 edges))
+                                   :max-height (- (nth 3 edges) (nth 1 edges)))
+                     keymap ,image-map
+                     modification-hooks
+                     (iimage-modification-hook)))
                 (remove-text-properties (match-beginning 0) (match-end 0)
                                         '(display modification-hooks))))))))))