Background
Eww, as many other packages, uses the display
text property to
display images. That is why toggling the invisible
text property
didn’t help. You’re making the text itself invisible but the display
property is still being shown.
In fact, this is something so common that the code below should work
on any buffer that displays images (not just eww).
Solution
The easiest solution is to just remove the display
property from the
entire buffer. But that’s an irreversible action, you wouldn’t be able
to turn images back on without refreshing the page.
The more robust solution, presented below, removes display
properties in the buffer and simultaneously backs-up the image to
another (useless) property. When called again, the command moves the
backed up images back into the display
property.
(defvar-local endless/display-images t)
(defun endless/toggle-image-display ()
"Toggle images display on current buffer."
(interactive)
(setq endless/display-images
(null endless/display-images))
(endless/backup-display-property endless/display-images))
This is the guy who does the backup and restore everywhere. Text
property code isn’t terribly easy to read, but I think this function
is short enough to be self explanatory.
(defun endless/backup-display-property (invert &optional object)
"Move the 'display property at POS to 'display-backup.
Only applies if display property is an image.
If INVERT is non-nil, move from 'display-backup to 'display
instead.
Optional OBJECT specifies the string or buffer. Nil means current
buffer."
(let* ((inhibit-read-only t)
(from (if invert 'display-backup 'display))
(to (if invert 'display 'display-backup))
(pos (point-min))
left prop)
(while (and pos (/= pos (point-max)))
(if (get-text-property pos from object)
(setq left pos)
(setq left (next-single-property-change pos from object)))
(if (or (null left) (= left (point-max)))
(setq pos nil)
(setq prop (get-text-property left from object))
(setq pos (or (next-single-property-change left from object)
(point-max)))
(when (eq (car prop) 'image)
(add-text-properties left pos (list from nil to prop) object))))))
Please to let me know if it works! I only tested it on very simple webpages.