(url-store-in-cache image-buffer)
(when (or (search-forward "\n\n" nil t)
(search-forward "\r\n\r\n" nil t))
- (let ((data (buffer-substring (point) (point-max))))
+ (let ((data (shr-parse-image-data)))
(with-current-buffer buffer
(save-excursion
(let ((alt (buffer-substring start end))
(setq payload (base64-decode-string payload)))
payload)))
-(defun shr-put-image (data alt &optional flags)
- "Put image DATA with a string ALT. Return image."
+(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 100))
+ (create-image data nil t :ascent 100
+ :content-type content-type))
((eq size 'full)
(ignore-errors
- (shr-rescale-image data t)))
+ (shr-rescale-image data t content-type)))
(t
(ignore-errors
- (shr-rescale-image data))))))
+ (shr-rescale-image data nil content-type))))))
(when image
;; When inserting big-ish pictures, put them at the
;; beginning of the line.
image)
(insert alt)))
-(defun shr-rescale-image (data &optional force)
+(defun shr-rescale-image (data &optional force content-type)
"Rescale DATA, if too big, to fit the current buffer.
If FORCE, rescale the image anyway."
(if (or (not (fboundp 'imagemagick-types))
:max-width (truncate (* shr-max-image-proportion
(- (nth 2 edges) (nth 0 edges))))
:max-height (truncate (* shr-max-image-proportion
- (- (nth 3 edges) (nth 1 edges))))))))
+ (- (nth 3 edges) (nth 1 edges))))
+ :content-type content-type))))
;; url-cache-extract autoloads url-cache.
(declare-function url-cache-create-filename "url-cache" (url))
t)
(when (or (search-forward "\n\n" nil t)
(search-forward "\r\n\r\n" nil t))
- (buffer-substring (point) (point-max))))))
+ (shr-parse-image-data)))))
+
+(defun shr-parse-image-data ()
+ (list
+ (buffer-substring (point) (point-max))
+ (save-excursion
+ (save-restriction
+ (narrow-to-region (point-min) (point))
+ (let ((content-type (mail-fetch-field "content-type")))
+ (and content-type
+ (intern content-type obarray)))))))
(defun shr-image-displayer (content-function)
"Return a function to display an image.