I would like to convert and display webp images – while having a fallback to other formats jpg/png for those browsers that don’t support modern image formats. I don’t want different dimensions (responsive images).
I’ve been trying to follow
But I don’t find it easy to understand. I’ve got this block snippet
<?php if ($image = $block->event_photo()->toFile()): ?>
<picture>
<source srcset="<?= $image->srcset('extra-images-webp') ?>" type="image/webp">
<img
alt="<?= $image->alt() ?>"
src="<?= $image->thumb(['width' => 780, 'height' => 520, 'crop' => 'center'])->url() ?>"
width="780"
height="520"
>
</picture>
<?php endif ?>
And this config.php file
<?php
return [
'debug' => false,
'thumbs' => [
'srcsets' => [
'hero-images' => [
'780w' => ['width' => 780, 'height' => 520, 'crop' => 'center'],
'1200w' => ['width' => 1200, 'height' => 800, 'crop' => 'center'],
'1600w' => ['width' => 1600, 'height' => 1066, 'crop' => 'center']
],
'hero-images-webp' => [
'780w' => ['width' => 780, 'height' => 520, 'crop' => 'center', 'format' => 'webp'],
'1200w' => ['width' => 1200, 'height' => 800, 'crop' => 'center', 'format' => 'webp'],
'1600w' => ['width' => 1600, 'height' => 1066, 'crop' => 'center', 'format' => 'webp']
],
'extra-images' => [
'780w' => ['width' => 780, 'height' => 520, 'crop' => 'center']
],
'extra-images-webp' => [
'780w' => ['width' => 780, 'height' => 520, 'crop' => 'center', 'format' => 'webp']
],
'news-images' => [
'780w' => ['width' => 780]
],
'news-images-webp' => [
'780w' => ['width' => 780, 'format' => 'webp']
],
// more srcsets as needed
]
]
];
Is this correct?
Rather than have to write this out in full in my block
src="<?= $image->thumb(['width' => 780, 'height' => 520, 'crop' => 'center'])->url() ?>"
Is it possible to link to the config file?