diff options
author | Lars Ingebrigtsen <larsi@gnus.org> | 2020-08-03 09:00:53 +0200 |
---|---|---|
committer | Lars Ingebrigtsen <larsi@gnus.org> | 2020-08-03 09:00:53 +0200 |
commit | 79527cd56e9e3f8b5b1630fe18b92f7ea95e87fd (patch) | |
tree | cfb1242d8ab309be5fa7d0fc04073dd35f728282 | |
parent | 26b9a1da63bab8c8ee00a484df46db6ed57e2317 (diff) | |
download | emacs-79527cd56e9e3f8b5b1630fe18b92f7ea95e87fd.tar.gz emacs-79527cd56e9e3f8b5b1630fe18b92f7ea95e87fd.tar.bz2 emacs-79527cd56e9e3f8b5b1630fe18b92f7ea95e87fd.zip |
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).
-rw-r--r-- | lisp/image-mode.el | 23 |
1 files 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) |