Function: shr-rescale-image
shr-rescale-image is a byte-compiled function defined in shr.el.gz.
Signature
(shr-rescale-image DATA CONTENT-TYPE WIDTH HEIGHT &optional MAX-WIDTH MAX-HEIGHT)
Documentation
Rescale DATA, if too big, to fit the current buffer.
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.
Source Code
;; Defined in /usr/src/emacs/lisp/net/shr.el.gz
(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.
The size of the displayed image will not exceed
MAX-WIDTH/MAX-HEIGHT. If not given, use the current window
width/height instead."
(if (not (get-buffer-window (current-buffer) t))
(create-image data nil t :ascent shr-image-ascent)
(let* ((edges (window-inside-pixel-edges
(get-buffer-window (current-buffer))))
(max-width (truncate (* shr-max-image-proportion
(or max-width
(- (nth 2 edges) (nth 0 edges))))))
(max-height (truncate (* shr-max-image-proportion
(or max-height
(- (nth 3 edges) (nth 1 edges))))))
(scaling (image-compute-scaling-factor image-scaling-factor)))
(when (or (and width
(> width max-width))
(and height
(> height max-height)))
(setq width nil
height nil))
(if (and width height
(< (* width scaling) max-width)
(< (* height scaling) max-height))
(create-image
data (shr--image-type) t
:ascent shr-image-ascent
:width width
:height height
:format content-type)
(create-image
data (shr--image-type) t
:ascent shr-image-ascent
:max-width max-width
:max-height max-height
:format content-type)))))