How to use built-in image focus method

What is the syntax to use ->focus() in Kirby 4? I didn’t see any template guidance on the announcement page.

Can’t wait to use it!

This works but it looks to complicated to be true:

$image->crop(400, 300, ['crop' => $image->focus()->isEmpty() ? 'center' : $image->focus()]);

Focus settings should be automatically applied when you use `crop()

Yes, works for me now! It may be obvious to others, but instead of just removing the old focus plugin, I also had to remove the focus: field in my default image blueprint in order for the new focus to work.

1 Like

It may be obvious to others, but instead of just removing the old focus plugin, I also had to remove the focus: field in my default image blueprint in order for the new focus to work.

Thanks for that tip, was wondering why the focus point wasn’t persisting.

But we can use the focus with ->crop() AND the ->thumb() function (with crop=>true for additional webp), right?

@Shel thanks for mentioning. In my test it does require the ->thumb() method in order for the ['format' => 'webp'] to work. And thumb is using my focus setting by default.

Hm, for some reason neither this

$img->thumb(['crop' => 'true', 'width' => 800, 'height' => 800, 'format' => 'webp'])->url()

Or this

$image->crop(800, 800)->url()

don’t use the focus point for me. It just crops centered as usual. I checked the .txt files for files, and the focus data is there. In the panel, the image is cropped correctly, but on the front end is still the center crop.

Rechecked: this $image->crop(800, 800)->url() works.

But this $img->thumb(['crop' => 'true', 'width' => 800, 'height' => 800, 'format' => 'webp'])->url() doesn’t. Hm…

You need to use a boolean, not a string “true”

1 Like

Oh dear :face_with_peeking_eye: Yup, it works now!

Thank you, Sonja! :pray: