缩放和裁剪图像

时间:2017-02-01 11:21:03

标签: php image symfony ezpublish ezplatform

我试图缩放图像并从中心裁剪到一定大小。

基本上,如果我想要图像为240x160(比例为1.5:1)并且我的图像为900x800(比例为1.125:1)并使用这些设置:

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

但我无法获得理想的结果。

2 个答案:

答案 0 :(得分:3)

在您网站image_variations的网站设置栏中,尝试添加以下内容:

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

上面的块会做两件事。首先,您的图像将缩小到适当的大小(您已经拥有该位)。接下来,缩略图过滤器将从中间(中心裁剪)裁剪图像到所需的尺寸。

答案 1 :(得分:1)

我相信您追逐的结果符合以下配置:

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

此设置将产生缩小到中心的缩小版本(达到您想要的大小)。 假设您正在使用ezplatform的已实现的image-alias-system系统。

希望您正在寻找答案:)