Reference

Guide

$file->srcset()

Create a srcset definition for the given sizes Sizes can be defined as a simple array. They can also be set up in the config with the thumbs.srcsets option.

$file->srcset(array|string $sizes = null): string|null

Parameters

Name Type Default Description
$sizes array|string null

Return type

string|null

Example

<img
src="<?= $image->url() ?>"
srcset="<?= $image->srcset([300, 800, 1024]) ?>" />

Modify width definition

$image->srcset([
  800  => '1x',
  1600 => '1.5x'
]);

Define presets

site/config/config.php
return [
  'thumbs' => [
    'srcsets' => [
            'default' => [300, 800, 1024],
            'cover' => [800, 1024, 2048]
        ]
  ]
];
// default preset
$image->srcset();

// particular preset
$image->srcset('cover');

Source code

kirby/src/Cms/FileModifications.php#L110