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.

FLAGS is a property list specifying optional parameters for the image. You can specify the following optional properties:

* :zoom: The zoom level for the image. One of default, original,
  or full.
* :width: The width of the image as specified by the HTML "width"
  attribute.
* :height: The height of the image as specified by the HTML
  "height" attribute.

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.

FLAGS is a property list specifying optional parameters for the image.
You can specify the following optional properties:

* `:zoom': The zoom level for the image.  One of `default', `original',
  or `full'.
* `:width': The width of the image as specified by the HTML \"width\"
  attribute.
* `:height': The height of the image as specified by the HTML
  \"height\" attribute."
  (if (display-graphic-p)
      (let* ((zoom (or (plist-get flags :zoom)
                       (car shr-image-zoom-levels)))
             (zoom-function (or (nth 2 (assq zoom shr-image-zoom-level-alist))
                                (error "Unrecognized zoom level %s" zoom)))
	     (data (if (consp spec)
		       (car spec)
		     spec))
	     (content-type (and (consp spec)
				(cadr spec)))
	     (start (point))
	     (image (ignore-errors
                      (funcall zoom-function 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))
                  image-height body-height)
	      (if (and shr-sliced-image-height
                       (setq image-height (cdr (image-size image t))
                             body-height (window-body-height
                                          (get-buffer-window (current-buffer))
                                          t))
                       (> (/ image-height body-height 1.0)
                          shr-sliced-image-height))
                  ;; 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 (/ image-height (default-line-height)) 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-zoom zoom)
	      (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 ""))))