Crop hardcoded image

I’m using/linking to an image directly in my template (it is not part of the Panel). Can I crop this image? The following thumb method doesn’t work

<img src="<?= url('/home/15096-084.jpg')->crop(408, 272) ?>">

Neither does

<img src="<?= crop(408, 272)->url('/home/15096-084.jpg') ?>">

I think you need to turn it into an asset first, and its generally good practice to keep such images under the assets folder.

but as its in the content folder, you can call it by name and from there the image methods will work.

$page->image() | Kirby CMS.

Something like this should work:

<?php if($image = $site->find('home')->image('15096-084.jpg')): ?>
<img src="<?= $image->url() ?>" alt="">
<?php endif ?>
1 Like

Thank you!