podlove / podlove-publisher

Podlove Podcast Publisher for WordPress
https://wordpress.org/plugins/podlove-podcasting-plugin-for-wordpress/
MIT License
299 stars 84 forks source link

Cover art URL fallback for Auphonic does not use largest image from `img` `srcset` #1347

Open lumaxis opened 1 year ago

lumaxis commented 1 year ago

This is an issue I discovered this week with a change I added in https://github.com/podlove/podlove-publisher/pull/1241

In this code

https://github.com/podlove/podlove-publisher/blob/52e146f0317e26df698b11659eca243288d7582e/lib/modules/auphonic/admin.js#L274-L275

the element selected by $('#set-post-thumbnail > img').attr('src') looks something like this:

<a href="https://example.com/wp-admin/media-upload.php?post_id=12345&amp;type=image&amp;TB_iframe=1"
  id="set-post-thumbnail" aria-describedby="set-post-thumbnail-desc" class="thickbox">
  <img width="266" height="266" src="https://example.com/wp-content/uploads/2022/12/123-350x350.jpg"
    class="attachment-266x266 size-266x266" alt="" decoding="async" loading="lazy"
    srcset="https://example.com/wp-content/uploads/2022/12/123-350x350.jpg 350w, https://example.com/wp-content/uploads/2022/12/123-577x577.jpg 577w, https://example.com/wp-content/uploads/2022/12/123-1000x1000.jpg 1000w, https://example.com/wp-content/uploads/2022/12/123-150x150.jpg 150w, https://example.com/wp-content/uploads/2022/12/123-50x50.jpg 50w, https://example.com/wp-content/uploads/2022/12/123-125x125.jpg 125w, https://example.com/wp-content/uploads/2022/12/123-100x100.jpg 100w, https://example.com/wp-content/uploads/2022/12/123-250x250.jpg 250w, https://example.com/wp-content/uploads/2022/12/123.jpg 1230w"
    sizes="(max-width: 266px) 100vw, 266px">
</a>

That means, Podlove Publisher sends https://example.com/wp-content/uploads/2022/12/123-350x350.jpg to Auphonic which is much smaller than the original size image which would be https://example.com/wp-content/uploads/2022/12/123.jpg and is contained in the srcset attribute.

Expected behavior

Podlove Publisher uses the widest image available from srcset or falls back to src.

Actual behavior

Podlove Publisher always uses src

lumaxis commented 1 year ago

I'm happy to propose a fix for this but wanted to open an issue for feedback/context either way. My suggestion would be to iterate through srcset and find the largest image and optionally fall back to src.