I’m attempting to create a snippet that I can reuse for images that’s heavily inspired by the ‘Responsive images’ cookbook. Here’s what I have:
<?php
$breakpoints = "(min-width: 75em)".$sizes[2].",
(min-width: 60em)".$sizes[1].",
(min-width: 44em)".$sizes[0].",
100vw";
if($image): ?>
<picture>
<source
srcset="<?= $image->srcset('webp') ?>"
sizes="<?= $breakpoints ?>"
type="image/webp"
>
<img
alt="<?= $image->alt() ?>"
src="<?= $image->resize(400)->url() ?>"
srcset="<?= $image->srcset() ?>"
sizes="<?= $breakpoints ?>"
width="<?= $image->resize(1920)->width() ?>"
height="<?= $image->resize(1920)->height() ?>"
>
</picture>
<?php endif ?>
<?php snippet('image', ['image' => $image, 'sizes' => ['50vw','33vw','33vw']]); ?>
One thing I don’t quite understand are the resizes on the src and width and height attributes from the cookbook. The resize on src is just a fallback for browsers that don’t support srcset? If so, should this size be whatever the largest version needs to be? Also, the width and height, how are these relevant when using sizes, or are the also a fallback?