Function: shr-put-image
shr-put-image is a byte-compiled function defined in shr.el.gz.
Signature
(shr-put-image SPEC ALT &optional FLAGS)
Documentation
Insert image SPEC with a string ALT. Return image.
SPEC is either an image data blob, or a list where the first element is the data blob and the second element is the content-type.
Source Code
;; Defined in /usr/src/emacs/lisp/net/shr.el.gz
(defun shr-put-image (spec alt &optional flags)
"Insert image SPEC with a string ALT. Return image.
SPEC is either an image data blob, or a list where the first
element is the data blob and the second element is the content-type."
(if (display-graphic-p)
(let* ((size (cdr (assq 'size flags)))
(data (if (consp spec)
(car spec)
spec))
(content-type (and (consp spec)
(cadr spec)))
(start (point))
(image (cond
((eq size 'original)
(create-image data nil t :ascent shr-image-ascent
:format content-type))
((eq content-type 'image/svg+xml)
(when (image-type-available-p 'svg)
(create-image data 'svg t :ascent shr-image-ascent)))
((eq size 'full)
(ignore-errors
(shr-rescale-image data content-type
(plist-get flags :width)
(plist-get flags :height))))
(t
(ignore-errors
(shr-rescale-image data content-type
(plist-get flags :width)
(plist-get flags :height)))))))
(when image
;; The trailing space can confuse shr-insert into not
;; putting any space after inline images.
;; ALT may be nil when visiting image URLs in eww
;; (bug#67764).
(setq alt (string-trim (or alt "")))
(when (length= alt 0) (setq alt "*"))
;; When inserting big-ish pictures, put them at the
;; beginning of the line.
(let ((inline (shr--inline-image-p image)))
(when (and (> (current-column) 0)
(not inline))
(insert "\n"))
(let ((image-pos (point)))
(if (eq size 'original)
;; Normally, we try to keep the buffer text the same
;; by preserving ALT. With a sliced image, we have to
;; repeat the text for each line, so we can't do that.
;; Just use "*" for the string to insert instead.
(progn
(insert-sliced-image image "*" nil 20 1)
(let ((overlay (make-overlay start (point))))
;; Avoid displaying unsightly decorations on the
;; image slices.
(overlay-put overlay 'face 'shr-sliced-image)))
(insert-image image alt))
(put-text-property start (point) 'image-size size)
(when (and (not inline) shr-max-inline-image-size)
(insert "\n"))
(when (and shr-image-animate
(cdr (image-multi-frame-p image)))
(image-animate image nil 60 image-pos)))))
image)
(insert (or alt ""))))