I am trying to modify width definitions of srcset and having trouble. The following code works for me.
<img
src="<?= $album->cover()->url() ?>"
srcset="<?= $album->cover()->srcset([300, 800, 1024]) ?>" />
but I want to choose what image size to delivery at those breakpoints, and crop the image in the center. The ‘associated array of options’ is exactly what I need. Mentioned here in the docs.
Do I need both this:
$album->cover()->srcset([
800 => '1x',
1600 => '1.5x'
]);
AND this?
$album->cover()->srcset([
'1x' => [
'width' => 38,
'height' => 38,
'crop' => 'center'
],
'2x' => [
'width' => 76,
'height' => 76,
'crop' => 'center'
],
'3x' => [
'width' => 152,
'height' => 152,
'crop' => 'center'
]
]);
I tried to put use the associated array inline like this:
<img
src="<?= $album->cover()->url() ?>"
srcset="<?= $album->cover()->srcset([
'1x' => [
'width' => 38,
'height' => 38,
'crop' => 'center'
],
'2x' => [
'width' => 76,
'height' => 76,
'crop' => 'center'
],
'3x' => [
'width' => 152,
'height' => 152,
'crop' => 'center'
]
]); ?>"
/>
It doesn’t break entirely, but only delivers the 1x version. I don’t see how the browser would know what to do with ‘1x’ without something like this code block linking the two together.
$image->srcset([
800 => '1x',
1600 => '1.5x'
]);
but again, I don’t know where this would fit into the syntax, because the srcset attribute of the img tag is already full. Maybe it goes into the config file?
What is the syntax to implement what the second to last code block attempts to?