I use eww to open an image from wikipedia:
https://upload.wikimedia.org/wikipedia/commons/6/6a/The_Burning_of_the_Houses_of_Parliament.jpg
Now, I wanted to save it to my computer.
How can I do that?
I use eww to open an image from wikipedia:
https://upload.wikimedia.org/wikipedia/commons/6/6a/The_Burning_of_the_Houses_of_Parliament.jpg
Now, I wanted to save it to my computer.
How can I do that?
As far as I can tell *eww*
buffers store image data in the display
text property.
So, to save an image we need to get this property and save it to a file.
Here is a sketch of a solution.
(defun my-eww-save-image (filename)
"Save an image opened in an *eww* buffer to a file."
(interactive "G")
(let ((image (get-text-property (point-min) 'display)))
(with-temp-buffer
(setq buffer-file-name filename)
(insert
(plist-get (if (eq (car image) 'image) (cdr image)) :data))
(save-buffer))))
This code seems to work in the case I tested it on, but it has at least two flaws:
save-buffer
calls hooks in before-save-hooks
and after-save-hooks
, which does not really make sense here.If you know how to improve this, please go right ahead.