From 79527cd56e9e3f8b5b1630fe18b92f7ea95e87fd Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Mon, 3 Aug 2020 09:00:53 +0200 Subject: [PATCH] Fix problem with viewing .webp files from .zip buffers * lisp/image-mode.el (image-toggle-display-image): Make it possible to view images (via external formatters, like webp) from zip files (and other archive modes) (bug#39994). --- lisp/image-mode.el | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/lisp/image-mode.el b/lisp/image-mode.el index 129529542ae..c417be43da5 100644 --- a/lisp/image-mode.el +++ b/lisp/image-mode.el @@ -818,13 +818,21 @@ was inserted." (- (nth 2 edges) (nth 0 edges)))) (max-height (when edges (- (nth 3 edges) (nth 1 edges)))) - (type (if (image--imagemagick-wanted-p filename) - 'imagemagick - (image-type file-or-data nil data-p))) (inhibit-read-only t) (buffer-undo-list t) (modified (buffer-modified-p)) - props image) + props image type) + + ;; If the data in the current buffer isn't from an existing file, + ;; but we have a file name (this happens when visiting images from + ;; a zip file, for instance), provide a type hint based on the + ;; suffix. + (when (and data-p filename) + (setq data-p (intern (format "image/%s" + (file-name-extension filename))))) + (setq type (if (image--imagemagick-wanted-p filename) + 'imagemagick + (image-type file-or-data nil data-p))) ;; Get the rotation data from the file, if any. (when (zerop image-transform-rotation) ; don't reset modified value @@ -841,10 +849,13 @@ was inserted." ;; :scale 1: If we do not set this, create-image will apply ;; default scaling based on font size. (setq image (if (not edges) - (create-image file-or-data type data-p :scale 1) + (create-image file-or-data type data-p :scale 1 + :format (and filename data-p)) (create-image file-or-data type data-p :scale 1 :max-width max-width - :max-height max-height))) + :max-height max-height + ;; Type hint. + :format (and filename data-p)))) ;; Discard any stale image data before looking it up again. (image-flush image) -- 2.39.2