Resizing & cropping images
Kirby's built-in thumbs creator lets you resize and crop any image on the fly in your templates. You can not only resize and crop images from the content folder, but also from the assets folder directly.
With Kirby's new Thumbnail API, thumbs are generated asynchronously. This makes thumb creation feel a lot faster and creates less memory issues, which could easily become an issue with many images or when creating many different images sizes to serve responsive images.
A new set of plugin points can be used to hook into the thumbnail API or the thumbnail URLs, see core components.
In a default setup, thumbnails are stored in the /media
folder.
Resizing images
Cropping images
Square
Crop by width and height
Crop positions
You can set from which position a file should be cropped. The following crop options are available:
top left
top
top right
left
center
right
bottom left
bottom
bottom right
This is how to use the crop positions in your code:
Blur
The blur
method applies a blur filter to an image. You can modify the intensity of the blur effect by passing an integer. The default value is 10.
Grayscale
The grayscale method converts an image to grayscale.
Configuring your thumbnails
Options for thumbnails are set with the thumbs
key in Kirby's configuration:
Presets
Since 3.0.3
You can define option presets for thumbs in your config.php
:
Then you can use them e.g. in your templates:
Responsive images
Since 3.1.0
You can use Kirby's $image->srcset()
method to easily create the srcset
attribute for responsive images. Learn more ›