$asset
Anything in your public path can be converted to an Asset object to use the same handy file methods as for any other Kirby files. Pass a relative path to the class to create the asset.
- $asset->asset()
- $asset->blur()
- $asset->bw()
- $asset->crop()
- $asset->exists()
- $asset->grayscale()
- $asset->greyscale()
- $asset->id()
- $asset->kirby()
- $asset->mediaHash()
- $asset->mediaPath()
- $asset->mediaRoot()
- $asset->mediaUrl()
- $asset->path()
- $asset->quality()
- $asset->resize()
- $asset->root()
- $asset->sharpen()
- $asset->srcset()
- $asset->thumb()
- $asset->type()
- $asset->url()
- new Asset()
Details
You can create a new Asset object via the asset()
helper or via the class constructor:
The asset()
helper and Asset
class have access to the entire file system of your server as they are meant for flexible use and the provided paths can therefore not be validated by Kirby. Be careful about passing dynamic paths to it (especially paths that can be controlled from the request), as this may cause unexpected behavior or be abused by attackers.
Via the helper
$asset = asset('assets/images/logo.svg');
Via the constructor
$asset = new Asset('assets/images/logo.svg');
With the object defined, you can then start calling the class's methods:
if ($asset->exists()) {
echo $asset->width();
}