Closed wdebusschere closed 8 months ago
Hi @wdebusschere, I think the current behavior of imagex is correct and I intentionally made it not this strict so that it works with all kinds of setups and third party lazy loading libraries.
You can and should definitely set the "sizes" attribute. To add attributes to the <source>
tags simply set them via sourcesAttributes
, like this:
'sourcesAttributes' => ['shared' => ['sizes' => 'your-sizes-value']],
Here you can find a good example: https://github.com/timnarr/kirby-imagex/blob/main/docs/examples/loading-modes-eager-lazy.md#snippet-options
You can also set the sizes attribute via sourcesArtDirected
when you need to have different sizes
attribute for art-directed sources:
'sourcesArtDirected' => [
[
'ratio' => '21/9',
'media' => '(min-width: 800px)',
'image' => $block->imagetwo()->toFile(),
'attributes' => [
'shared' => [
'sizes' => 'your-sizes-value'
]
]
]
],
I hope this helps 🙂
Does this plugin works correctly for WebP or AVIF format? It always shows the largest format.
For us it works correctly if we add the sizes to the source in imagex-picture.php
<source <?= attr($source) ?> sizes="<?= $imgAttributes['sizes'] ?>" />