$file->resize()
Resizes the file with the given width and height while keeping the aspect ratio.
$file->resize(int|null $width = null, int|null $height = null, int|null $quality = null): Kirby\Cms\FileVersion|Kirby\Cms\File|Kirby\Filesystem\Asset
Parameters
| Name | Type | Default |
|---|---|---|
| $width | intornull |
null
|
| $height | intornull |
null
|
| $quality | intornull |
null
|
Return types
Kirby\Cms\FileVersionorKirby\Cms\FileorKirby\Filesystem\Asset
This method modifies the existing $file object it is applied to and returns it again.
Exceptions
| Type | Description |
|---|---|
Kirby\Exception\InvalidArgumentException |
Parent class
Examples
if ($image = $page->image()):
// resize by width and height and echo the url
echo $image->resize(300, 200);
// adjust the quality
echo $image->resize(300, 200, 80);
// resize by height
echo $image->resize(null, 200);
// resize by width
echo $image->resize(300);
endif;