Subject: Re: bug#71913: 29.1; shr: shr-resize-image does not behave as expected

From: Jim Porter <[email-masked]>
Date: Wed, 3 Jul 2024 08:48:46 -0700

On 7/2/2024 11:37 PM, George Huebner wrote:
> I noticed an issue with =shr-max-image-proportion= wherein images would 
> be correctly resized on initial load, but would then appear much larger.
[snip]
> Here's a minimal reproducible example (credit to Sacha Chua):
> #+begin_src elisp :eval no
> ;; run this (image is very large), run again many times without   
> killing *test* (image is correct size), kill *test* and run   again 
> (image is large again)
> ;; won't observe this behaviour if you disable cache
> ;; (setq shr-ignore-cache t)
> (setq shr-max-image-proportion 0.5)
> (with-current-buffer (get-buffer-create "*test*")
>   (erase-buffer)
>   (insert "<img 
>   src=\"https://upload.wikimedia.org/wikipedia/commons/8/83/The_GNU_logo.png\">")
>   (shr-insert-document (libxml-parse-html-region (point-min)  (point-max)))
>   (display-buffer (current-buffer)))
> #+end_src elisp

The bug here is really in your steps to reproduce, which I suppose is 
roughly what Elfeed is doing too (though I haven't looked at that code 
to be totally sure).

SHR scales images with respect to the size of the buffer's window. 
However, by rendering the HTML document with SHR *before* displaying the 
buffer in a window, it's impossible for Emacs to do that: there's no 
such window yet! If you swap the 'display-buffer' and 
'shr-insert-document' lines though, all should work properly.