summaryrefslogtreecommitdiff
path: root/lisp/net/shr.el
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2017-01-24 21:17:09 +0100
committerLars Ingebrigtsen <larsi@gnus.org>2017-01-24 21:17:45 +0100
commit37567393a033f3feeec3d6ace30fa2dcd0419e26 (patch)
tree95925fa4c8fcd763f6cadbe1a1b651434f81d80a /lisp/net/shr.el
parent52a87c894d1e2351baecaff9ff061e3b83827220 (diff)
downloademacs-37567393a033f3feeec3d6ace30fa2dcd0419e26.tar.gz
emacs-37567393a033f3feeec3d6ace30fa2dcd0419e26.tar.bz2
emacs-37567393a033f3feeec3d6ace30fa2dcd0419e26.zip
Allow passing in max-width/height
* lisp/net/shr.el (shr-rescale-image): Allow passing in max-width/height (bug#25287).
Diffstat (limited to 'lisp/net/shr.el')
-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."
image)
(insert (or alt ""))))
-(defun shr-rescale-image (data content-type width height)
+(defun shr-rescale-image (data content-type width height
+ &optional max-width max-height)
"Rescale DATA, if too big, to fit the current buffer.
-WIDTH and HEIGHT are the sizes given in the HTML data, if any."
+WIDTH and HEIGHT are the sizes given in the HTML data, if any.
+
+The size of the displayed image will not exceed
+MAX-WIDTH/MAX-HEIGHT. If not given, use the current window
+width/height instead."
(if (or (not (fboundp 'imagemagick-types))
(not (get-buffer-window (current-buffer))))
(create-image data nil t :ascent 100)
(let* ((edges (window-inside-pixel-edges
(get-buffer-window (current-buffer))))
(max-width (truncate (* shr-max-image-proportion
- (- (nth 2 edges) (nth 0 edges)))))
+ (or max-width
+ (- (nth 2 edges) (nth 0 edges))))))
(max-height (truncate (* shr-max-image-proportion
- (- (nth 3 edges) (nth 1 edges)))))
+ (or max-height
+ (- (nth 3 edges) (nth 1 edges))))))
(scaling (image-compute-scaling-factor image-scaling-factor)))
(when (or (and width
(> width max-width))