Scale and crop image

1.1k Views Asked by At

I'm trying to scale image and to crop it to certain size from center.

Basically if I want image to be 240x160 (scale 1.5:1) and I have Image that is 900x800 (scale 1.125:1) and use these settings:

filters:
    - { name: geometry/scaledownonly, params: [240, 160] }
    - { name: geometry/crop, params: [240, 160, 0, 0] }

But I cant get desired results.

2

There are 2 best solutions below

2
On BEST ANSWER

In your site image_variations block of your site settings yaml, try adding the following:

image_variation_name:
    reference: ~
    filters:
        - { name: geometry/scaledownonly, params: [240, 160] }
        - { name: thumbnail, params: { size: [240, 160], mode: outbound } }

The above block will do two things. First, your image will scaled down to the appropriate size (you already had that bit). Next, the thumbnail filter will crop the image from the middle out (center crop) to the desired dimentions.

0
On

I believe the result you chase after would fit to the following configuration:

...
image_variations:
    your_alias_name:
        reference: ~
        filters:
            thumbnail: { size: [240, 160], mode: outbound, allow_upscale: true }
...

This setting will yield a scaled down version cropped to the center (to you're desired size). That is assuming you are using the implemented image-alias-system of ezplatform though.

Hope thats the answer you are looking for :)