Yireo_Webp2 icon indicating copy to clipboard operation
Yireo_Webp2 copied to clipboard

Support existing <picture> structure

Open mattkrupnik opened this issue 2 years ago • 3 comments

Module works like charm for simple <img> elements but is any possibility to support existing <picture> element in code? I have in code existing <picture> structure and it doesn't supported.

<picture>
    <source media="(min-width: 480px)" srcset="https://example.com/media/image-for-desktop.jpg">
    <source media="(max-width: 480px)" srcset="https://example.com/media/image-for-mobile.jpg">
    <img src="https://example.com/media/image-for-desktop.jpg">
</picture>

Regards Matt

mattkrupnik avatar Oct 08 '21 19:10 mattkrupnik

@mattkrupnik @jissereitsma We came across this the other day. Self-closing your source tag fixes the issue (or did for us).

So: <picture> <source media="(min-width: 480px)" srcset="https://example.com/media/image-for-desktop.jpg" /> <source media="(max-width: 480px)" srcset="https://example.com/media/image-for-mobile.jpg" /> <img src="https://example.com/media/image-for-desktop.jpg"> </picture>

It's a workaround I guess, in the file yireo/magento2-next-gen-images/Image/HtmlReplacer.php on line 102 this could be added.

if ($nextTag === '/picture' || $nextTag === '/source') {

richjones87 avatar Oct 26 '21 09:10 richjones87

@richjones87 Thanks. I've released 0.2.11 of NextGenImages with this fix. However, I think it does not fix the issue for @mattkrupnik . As I understand it, the problem of @mattkrupnik (but correct me if I'm wrong) is that WebP alternatives are not added to the existing picture set. Adding that is actually quite complex and requires quite a bit more work ...

jissereitsma avatar Oct 26 '21 16:10 jissereitsma

@jissereitsma I see 😄 thanks for the update on the module.

richjones87 avatar Oct 27 '21 05:10 richjones87