Jump to content

Square thumbnails from landscape (or portrait) images

Recommended Posts


I'm converting again a website from another CMS to ProcessWire.

On the old website, there are square thumbnail images that were created manually back then, if I remember well.

The original images that I'm using again are in majority square images. But some are landscape images.
There could also be portrait images.

There will also be new images of different proportions.

I can't get the rectangle images to be cropped and reduced in size to 75 px.
The width is ok (in the case of landscape images of course) but the height is less than 75px.
The shortest side should be 75px and the longest side (centered) cropped in order to be 75px.

I am using Imagick by default, but I've also tried by setting its priority to 2 and 3.
So I've tried with GD with config.php by enabling cropping and/or by trying different settings directly in the template.

It doesn't change anything.

A square variation could be created in the backend but I'd prefer it to be done via the api in this case.

I'm not sure if I need to specify a condition where the height is not equal to the width of the image.
I thought it would work automatically with size() and cropping activated.
The cropping is normally centered by default if I'm not wrong (even though I've also tried by specifying it).

Thank you in advance for your help, hints...

If you need more details please let me know.

I'm using ProcessWire 3.0.212 dev with PHP 7.4.

Link to comment
Share on other sites

5 hours ago, Christophe said:

I thought it would work automatically with size() and cropping activated.

That's how it should be. Have you called $image->removeVariations() in between or added "forceNew" => true to your $options when calling $image->size(), to make sure the thumbnail is created from scratch?

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

Hello BitPoet,

I thought that I was "Following" by default because I had created the topic.
I received an email with the title "Did this answer your question?" the 20th March.

The project hasn't really started yet.
I'm waiting for more information to give a quote and continue to work on it.

Time has passed really quickly.
I'm moving from one house to another one so I didn't realize it.
I still have the desktop computer and the Internet in the old house for the moment.
In the new house there is no ADSL connection and the fiber/fibre one hasn't arrived yet in the street.

I've just added "forceNew" => true to my $options and have cleared the browser's cache, and it has just worked.
So, a Very Big Thank You!

After that, I've put it to false, to see later if I need to keep it to true or if I can just keep it deactivated from now on.
I haven't tried with $image->removeVariations() for the moment as it has worked with forceNew".
I've just realized that I had set cropping to false in $options after all the tests that hadn't worked, so it seems that it has fetched the square versions that already existed.
"$image->removeVariations() in between", you mean calling it just after using size(), or just before? I have a doubt.
You use size(), then remove variations, before calling the thumbnails? And that's why it has fetched the square versions even if "cropped" wasn't activated anymore?
Or you tell it to remove variations before using size()?
I guess it's what "forceNew" => true does, if one chooses this solution, or at what moment is "forceNew" => true applied?
I wonder why it didn't work without forceNew activated. It could be because of the server-specific cache...
I'm just curious...

Thank you again!

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

  • Recently Browsing   0 members

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