Image Function "Crop" shows an error

Hi,

The following code shows the image:

<?= $podcast_post->image() ?>

If i want to crop the image with:

<?= $podcast_post->image()->crop(300) ?>

I have got the error: “Call to a member function crop() on null”. Yes, i have not in every folder an image and i guessed to check with an if-statement this situation with:

<?php if($podcast_post->image()->isNotEmpty()): ?>
    <?= $podcast_post->image()->crop(300) ?>
<?php endif ?>

But then, i have got the next error: “Call to a member function isNotEmpty() on null”.

How can i eat the tomatoes on my eyes?

BR

isNotEmpty() is not the correct way to check if an image exists, it is a field method and a collection method, but we are neither dealing with a field nor with a collection in this case. So the correct way to do this is:

<?php if ($image = $podcast_post->image()) : ?>
    <?= $image->crop(300) ?>
<?php endif ?>
1 Like

Thank you so much.