Skip to content

Kirby 4.4.1

$file->thumb()

Creates a modified version of images The media manager takes care of generating those modified versions and putting them in the right place. This is normally the /media folder of your installation, but could potentially also be a CDN or any other place.

$file->thumb(array|string|null $options = null): Kirby\Cms\FileVersion|Kirby\Cms\File|Kirby\Filesystem\Asset

Parameters

Name Type Default
$options array|string|null null

Return type

Kirby\Cms\FileVersion|Kirby\Cms\File|Kirby\Filesystem\Asset

Exceptions

Parent class

Kirby\Cms\File

Options

Accepted types

Type Value
null Default preset from configuration if defined
string Name of preset defined in configuration
array See details below

If you pass an array as options, you can use the following key/value pairs (values are the default values):

$options = [
  'autoOrient' => true,
  'crop'       => false,
  'blur'       => false,
  'grayscale'  => false,
  'height'     => null,
  'quality'    => 90,
    'sharpen'    => false,
  'width'      => null,
];

You can also set the format option to convert an existing JPEG, GIF or PNG into a WebP or AVIF file method (value is the default value).

$options = [
  // other options
  'format'     => null,
];

You can define presets of options in your config.php. Learn more ›

Examples

if($image = $page->image()):
    echo $image->thumb([
      'width'   => 300,
      'height'  => 200,
      'quality' => 80,
    ])->html();
endif;
if($image = $page->image()):
    echo $image->thumb([
      'width'   => 300,
      'height'  => 200,
      'quality' => 80,
      'format'  => 'webp',
    ])->html();
endif;

If a focal point is set, this focal point will automatically be used when the crop option is set to true. If you use a custom crop position, this will overwrite the focal point set in the file metadata.