Jump to content

Image cropping doesn't work with custom center


Jozsef
 Share

Recommended Posts

The site is displaying a list of full body portraits that I'd like to crop with a focus on the face/shoulders.
No focus has been set on the images and it's hundreds of them so I want a sensible default.

This is the code below but it still crops from the top of the image, or the actual center (50%,50%).
Is it a bug or I'm doing something wrong?

$image = $gallery_page->images->first()->size(540,404,array("cropping" => array('50%','35%'), "quality" => 80))->webp->url;

It's based on the latest API reference I've found: https://processwire.com/api/ref/pageimage/size/
It's very late but is it something I can't spot here? Should it work?

Link to comment
Share on other sites

Thanks, it is not the problem, it would be cropped from the centre then. Interestingly, if the focus point is not set the images are cropped from North, not centre.

No matter what I tried, it doesn't work with percentages in the size options. I ended up setting the focus position for the image and it achieved the results.

if (!$image->hasFocus) $image->focus(35,50);
$resized = $image->size($w,$h)->webp->url;

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...