aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Ingebrigtsen2017-01-24 21:17:09 +0100
committerLars Ingebrigtsen2017-01-24 21:17:45 +0100
commit37567393a033f3feeec3d6ace30fa2dcd0419e26 (patch)
tree95925fa4c8fcd763f6cadbe1a1b651434f81d80a
parent52a87c894d1e2351baecaff9ff061e3b83827220 (diff)
downloademacs-37567393a033f3feeec3d6ace30fa2dcd0419e26.tar.gz
emacs-37567393a033f3feeec3d6ace30fa2dcd0419e26.zip
Allow passing in max-width/height
* lisp/net/shr.el (shr-rescale-image): Allow passing in max-width/height (bug#25287).
-rw-r--r--lisp/net/shr.el15
1 files changed, 11 insertions, 4 deletions
diff --git a/lisp/net/shr.el b/lisp/net/shr.el
index e0bb3dbb2b7..1c2ea3c7bc5 100644
--- a/lisp/net/shr.el
+++ b/lisp/net/shr.el
@@ -1011,18 +1011,25 @@ element is the data blob and the second element is the content-type."
1011 image) 1011 image)
1012 (insert (or alt "")))) 1012 (insert (or alt ""))))
1013 1013
1014(defun shr-rescale-image (data content-type width height) 1014(defun shr-rescale-image (data content-type width height
1015 &optional max-width max-height)
1015 "Rescale DATA, if too big, to fit the current buffer. 1016 "Rescale DATA, if too big, to fit the current buffer.
1016WIDTH and HEIGHT are the sizes given in the HTML data, if any." 1017WIDTH and HEIGHT are the sizes given in the HTML data, if any.
1018
1019The size of the displayed image will not exceed
1020MAX-WIDTH/MAX-HEIGHT. If not given, use the current window
1021width/height instead."
1017 (if (or (not (fboundp 'imagemagick-types)) 1022 (if (or (not (fboundp 'imagemagick-types))
1018 (not (get-buffer-window (current-buffer)))) 1023 (not (get-buffer-window (current-buffer))))
1019 (create-image data nil t :ascent 100) 1024 (create-image data nil t :ascent 100)
1020 (let* ((edges (window-inside-pixel-edges 1025 (let* ((edges (window-inside-pixel-edges
1021 (get-buffer-window (current-buffer)))) 1026 (get-buffer-window (current-buffer))))
1022 (max-width (truncate (* shr-max-image-proportion 1027 (max-width (truncate (* shr-max-image-proportion
1023 (- (nth 2 edges) (nth 0 edges))))) 1028 (or max-width
1029 (- (nth 2 edges) (nth 0 edges))))))
1024 (max-height (truncate (* shr-max-image-proportion 1030 (max-height (truncate (* shr-max-image-proportion
1025 (- (nth 3 edges) (nth 1 edges))))) 1031 (or max-height
1032 (- (nth 3 edges) (nth 1 edges))))))
1026 (scaling (image-compute-scaling-factor image-scaling-factor))) 1033 (scaling (image-compute-scaling-factor image-scaling-factor)))
1027 (when (or (and width 1034 (when (or (and width
1028 (> width max-width)) 1035 (> width max-width))