Replies: 2 comments 5 replies
-
Hi @hpfast The picture plugin outputs In short, the plugin only handles the combination of different formats and pixel densities. It doesn't handle media queries because it would be complicated and tricky (there are infinite combinations). But I had a similar request the other day on discord and I'm thinking on implementing support for <picture>
<source srcset="/img/img.jpg" media="(min-width: 1920px)" transform-images="webp avif">
<source srcset="/img/img.jpg" media="(min-width: 1280px)" transform-images="webp avif 1280">
<source srcset="/img/img.jpg" media="(min-width: 480px)" transform-images="webp avif 480">
<img alt="…" src="/img/img.jpg" transform-images="webp">
</picture> Supporting this, you could create a What do you think? If you like the idea and want ho help with that, I'll appreciate a lot. |
Beta Was this translation helpful? Give feedback.
-
The more I study it, the more it seems like my use-case should already be supported. Either I've found a bug or I'm doing something wrong.
I'd like to extract this from my project and make an isolated test case, alongside a reference implementation of <picture> and <img>, but I need to do some other things first. I'll get back with this soon
…On Tuesday, July 30th, 2024 at 12:49, Óscar Otero ***@***.***> wrote:
Sizes attribute is already supported (see PR here: [#482](#482))
I like the idea of making srcset optional in the <source> (taking the value of the <img> as default). So the input code of my example would be simpler:
<
picture
>
<
source
media
="
(min-width: 1920px)
"
transform-images
="
webp avif
"
>
<
source
media
="
(min-width: 1280px)
"
transform-images
="
webp avif 1280
"
>
<
source
media
="
(min-width: 480px)
"
transform-images
="
webp avif 480
"
>
<
img
alt
="
…
"
src
="
/img/img.jpg
"
>
</
picture
>
I rather only one attribute (transform-images) instead of adding additional attributes because it's clearer, specially if you want to override them.
This attribute can handle values of different types that the plugin understand. For example in avif webp ***@***.***, avif and webp are formats and 300 is a image size (adding @2 to create a version for 2x density). Maybe we can include [number]w syntax to generate images of a specific width, without taking into account the density. I.e. avif webp 300w.
—
Reply to this email directly, [view it on GitHub](#637 (reply in thread)), or [unsubscribe](https://github.com/notifications/unsubscribe-auth/AA35I2W6KD6W36UEZRVMVQDZO5VUHAVCNFSM6AAAAABLUDM2Y6VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTAMJYHE2DGMI).
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Hello @oscarotero !
I have been studying the picture plugin the last few days, and come to the conclusion (correct me if I'm wrong) that it supports one of multiple Responsive Images use cases:
a. resolution-switching, i.e. telling the browser about different sizes of images to use with media queries (not supported; needs an
<img>
withsrcset
andsizes
but the plugin outputs<picture>
elements)b. multiple filetypes and pixel densities to allow the browser to choose the best one (supported)
c. art direction, i.e. directing the browser to use different versions of images with media queries, e.g. a cropped version on narrow screens (not supported; needs a
media
attribute on the<source>
element in<picture>
but the plugin doesn't support that);(see MDN for an overview of these use-cases).
What I did for my immediate use-case ((a) above) was create a new plugin copying lots of the code, but only outputting
<img>
s. I also had to add a shared data file as well as another processing step to add thesizes
property to images before my plugin ran and to handle some conditional cases. All in all, it was quite straightforward to adapt, and the flexibility of Lume's processing mechanism is very nice.However, there is a bunch of helper code in the Picture plugin which it would be a pity to re-implement (creating the sources and transforms and such).
I was wondering:
Cheers!
Hans
Beta Was this translation helpful? Give feedback.
All reactions