$file->crop()
Crops the image by the given width and height
$file->crop(int $width, ?int $height = null, string|array $options = null): Kirby\Cms\FileVersion|Kirby\Cms\File
Parameters
| Name | Type | Default |
|---|---|---|
| $width * | int |
– |
| $height | int|null |
null |
| $options | string|array |
null |
Return type
Kirby\Cms\FileVersion|Kirby\Cms\File
Parent class
Example
if($image = $page->image()):
// crop into a square of 300 x 300
echo $image->crop(300);
// crop by height as well
echo $image->crop(300, 200);
// adjust the quality
echo $image->crop(300, 200, 70);
endif;
Crop positions
You can define from which side or corner a file should be cropped. The following crop options are available:
top lefttoptop rightleftcenterrightbottom leftbottombottom right
This is how to use the crop positions in your code:
// quick and simple
$image->crop(100, 200, 'top right');
// more fine grained control
$image->crop(100, 200, [
'quality' => 70,
'crop' => 'left'
]);