Fix: (ement-room-image-show) Handle invalid images

This commit is contained in:
Adam Porter 2021-07-29 18:07:56 -05:00
parent 28528ebdbd
commit 62a740aa9d

View file

@ -1705,25 +1705,27 @@ show it in the buffer."
(if (and ement-room-images image) (if (and ement-room-images image)
;; Images enabled and image downloaded: create image and ;; Images enabled and image downloaded: create image and
;; return it in a string. ;; return it in a string.
(let ((image (create-image image nil 'data-p :ascent 'center)) (condition-case err
(buffer-window (when buffer (let ((image (create-image image nil 'data-p :ascent 'center))
(get-buffer-window buffer))) (buffer-window (when buffer
max-height max-width) (get-buffer-window buffer)))
;; Calculate max image display size. max-height max-width)
(cond (buffer-window ;; Calculate max image display size.
;; Buffer displayed: use window size. (cond (buffer-window
(setf max-height (window-body-height buffer-window t) ;; Buffer displayed: use window size.
max-width (window-body-width buffer-window t))) (setf max-height (window-body-height buffer-window t)
(t max-width (window-body-width buffer-window t)))
;; Buffer not displayed: use frame size. (t
(setf max-height (frame-pixel-height) ;; Buffer not displayed: use frame size.
max-width (frame-pixel-width)))) (setf max-height (frame-pixel-height)
(setf (image-property image :type) 'imagemagick max-width (frame-pixel-width))))
(image-property image :max-width) max-width (setf (image-property image :type) 'imagemagick
(image-property image :max-height) max-height) (image-property image :max-width) max-width
(concat "\n" (image-property image :max-height) max-height)
(propertize " " 'display image (concat "\n"
'keymap ement-room-image-keymap))) (propertize " " 'display image
'keymap ement-room-image-keymap)))
(error (format "\n [error inserting image: %s]" (error-message-string err))))
;; Image not downloaded: insert URL as button, and download if enabled. ;; Image not downloaded: insert URL as button, and download if enabled.
(prog1 (prog1
(with-temp-buffer (with-temp-buffer