If $file->srcset() gets passed one or multiple image width(s) that are larger than the source image, the resulting srcset string includes those sizes as well. The linked thumb is of course not upscaled, but the browser only knows after requesting the image.
Expected behavior
Widths that are larger than the source should be filtered out and the source width as maximum option should be added instead.
To reproduce
With a source image of 750px width
echo $file->srcset([300, 500, 1000, 1500]);
all those sizes are printed. Instead, the result should be 300, 500, 750.
Your setup
Kirby Version
develop branch
Additional context
Things to keep in mind:
If an options array is passed as value, we cannot reliably filter out sizes. So in this case, the behavior should be unchanged. So only the "width as key" and "width as value" cases make sense to handle automatically.
If multiple sizes above the source width are passed, the source width should still only be added once.
If the source width was already passed, it should also not be added a second time.
Description
If
$file->srcset()
gets passed one or multiple image width(s) that are larger than the source image, the resultingsrcset
string includes those sizes as well. The linked thumb is of course not upscaled, but the browser only knows after requesting the image.Expected behavior
Widths that are larger than the source should be filtered out and the source width as maximum option should be added instead.
To reproduce
With a source image of 750px width
all those sizes are printed. Instead, the result should be
300, 500, 750
.Your setup
Kirby Version
develop
branchAdditional context
Things to keep in mind: