跳到内容

尺寸过滤器

编辑此页

缩略图

内置的 thumbnail 过滤器执行缩略图转换(包括缩放和可能的裁剪操作)。此过滤器公开了许多缩略图选项,可用于配置其行为。

配置示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# app/config/config.yml

liip_imagine:
    filter_sets:

        # name our filter set "my_thumb_filter"
        my_thumb_filter:
            filters:

                # use and setup the "thumbnail" filter
                thumbnail:

                    # set the thumbnail size to "32x32" pixels
                    size: [32, 32]

                    # crop the input image, if required
                    mode: outbound

参见

基本用法:创建缩略图章节提供了更多示例。

缩略图选项

mode: string
设置所需的调整大小方法:'outbound' 会根据需要裁剪图像,而 'inset' 执行非裁剪的相对调整大小。
size: int[]
将生成的缩略图大小设置为整数数组,其中包含宽度和高度值作为尺寸。
allow_upscale: bool
当图像小于所需的缩略图大小时,切换是否允许图像放大。

固定尺寸

内置的 fixed 过滤器执行缩略图转换(包括缩放和可能的裁剪操作)。此过滤器公开了许多固定选项,可用于配置其行为。与 thumbnail 过滤器不同,fixed 过滤器支持放大,并且您始终获得固定大小的图像。

配置示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# app/config/config.yml

liip_imagine:
    filter_sets:

        # name our filter set "my_fixed_filter"
        my_fixed_filter:
            filters:

                # use and setup the "fixed" filter
                fixed:

                    # set the fixed size to "120x90" pixels
                    width: 120
                    height: 90

固定选项

width: int
设置“所需宽度”,这将启动按比例缩放操作,该操作会向上或向下缩放,直到图像宽度与此值匹配。
height: int
设置“所需高度”,这将启动按比例缩放操作,该操作会向上或向下缩放,直到图像高度与此值匹配。

裁剪图像

内置的 crop 过滤器执行尺寸转换(包括裁剪操作)。此过滤器公开了许多裁剪选项,可用于配置其行为。

配置示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# app/config/config.yml

liip_imagine:
    filter_sets:

        # name our filter set "my_crop_filter"
        my_crop_filter:
            filters:

                # use and setup the "crop" filter
                crop:

                    # set the size of the cropping area
                    size: [ 300, 600 ]

                    # set the starting coordinates of the crop
                    start: [ 040, 160 ]

裁剪选项

size: int[]
将裁剪尺寸设置为整数数组,其中包含宽度和高度值作为尺寸。
start: int[]
设置裁剪操作开始的左上角锚点坐标。

相对调整大小

内置的 relative_resize 过滤器执行尺寸转换(特别是相对调整大小)。此过滤器公开了许多相对调整大小选项,可用于配置其行为。

配置示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# app/config/config.yml

liip_imagine:
    filter_sets:

        # name our first filter set "my_heighten_filter"
        my_heighten_filter:
            filters:

                # use and setup the "relative_resize" filter
                relative_resize:

                    # given 50x40px, output 75x60px using "heighten" option
                    heighten: 60

        # name our second filter set "my_widen_filter"
        my_widen_filter:
            filters:

                # use and setup the "relative_resize" filter
                relative_resize:

                    # given 50x40px, output 32x26px using "widen" option
                    widen: 32

        # name our second filter set "my_increase_filter"
        my_increase_filter:
            filters:

                # use and setup the "relative_resize" filter
                relative_resize:

                    # given 50x40px, output 60x50px, using "increase" option
                    increase: 10

        # name our second filter set "my_scale_filter"
        my_scale_filter:
            filters:

                # use and setup the "relative_resize" filter
                relative_resize:

                    # given 50x40px, output 125x100px using "scale" option
                    scale: 2.5

提示

“相对调整大小”过滤器选项直接映射到 BoxInterface 接口的方法,该接口由 Imagine Library 提供。

相对调整大小选项

heighten: float
设置“所需高度”,这将启动按比例缩放操作,该操作会向上或向下缩放,直到图像高度与此值匹配。
widen: float
设置“所需宽度”,这将启动按比例缩放操作,该操作会向上或向下缩放,直到图像宽度与此值匹配。
increase: float
设置“所需的附加尺寸”,这将启动通过将此值添加到图像所有边来计算的缩放操作。
scale: float
设置“比例倍数”,这将启动通过将图像所有边乘以该值来计算的比例缩放操作。

缩放

内置的 scale 过滤器执行尺寸转换(特别是图像缩放)。此过滤器公开了许多缩放选项,可用于配置其行为。

配置示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# app/config/config.yml

liip_imagine:
    filter_sets:

        # name our first filter set "my_ratio_down_scale_filter"
        my_ratio_down_scale_filter:
            filters:

                # use and setup the "scale" filter
                scale:

                    # given 1920x1600px -> output 960x800px (relative down-scale)
                    to: 0.5

        # name our first filter set "my_ratio_up_scale_filter"
        my_ratio_up_scale_filter:
            filters:

                # use and setup the "scale" filter
                scale:

                    # given 1920x1600px -> output 5760x3200px (relative up-scale)
                    to: 2

        # name our third filter set "my_dim_down_scale_filter"
        my_dim_down_scale_filter:
            filters:

                # use and setup the "scale" filter
                scale:

                    # input 1200x1600px -> output 750x1000px (relative down-scale)
                    dim: [ 800, 1000 ]

        # name our fourth filter set "my_dim_up_scale_filter"
        my_dim_up_scale_filter:
            filters:

                # use and setup the "scale" filter
                scale:

                    # input 300x900px -> output 900x2700px (relative up-scale)
                    dim: [ 1200, 2700 ]

缩放选项

dim: int[]
将“所需尺寸”设置为包含宽度和高度整数的数组,从中在此约束内执行相对调整大小。
to: float
设置“比例倍数”,这将启动通过将图像所有边乘以该值来计算的比例缩放操作。

缩小

内置的 downscale 过滤器执行尺寸转换(特别是图像缩小)。此过滤器公开了许多缩小选项,可用于配置其行为。

配置示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# app/config/config.yml

liip_imagine:
    filter_sets:

        # name our first filter set "my_max_down_scale_filter"
        my_max_down_scale_filter:
            filters:

                # use and setup the "downscale" filter
                downscale:

                    # input 3960x2560px -> output 1980x1280px
                    max: [1980, 1280]

        # name our second filter set "my_by_down_scale_filter"
        my_by_down_scale_filter:
            filters:

                # use and setup the "downscale" filter
                downscale:

                    # input 1980x1280px -> output 792x512px
                    by: 0.6

缩小选项

max: int[]
将“所需最大尺寸”设置为包含宽度和高度整数的数组,从中执行缩小以满足传递的约束。
by: float
设置“比例倍数”,这将启动通过将图像所有边乘以该值来计算的比例缩放操作。

放大

内置的 upscale 过滤器执行尺寸转换(特别是图像放大)。此过滤器公开了许多放大选项,可用于配置其行为。

配置示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# app/config/config.yml

liip_imagine:
    filter_sets:

        # name our first filter set "my_min_up_scale_filter"
        my_min_up_scale_filter:
            filters:

                # use and setup the "upscale" filter
                upscale:

                    # input 1980x1280px -> output 3960x2560px
                    min: [3960, 2560]

        # name our second filter set "my_by_up_scale_filter"
        my_by_up_scale_filter:
            filters:

                # use and setup the "upscale" filter
                upscale:

                    # input 800x600px -> output 1360x1020px
                    by: 0.7

放大选项

min: int[]
将“所需最小尺寸”设置为包含宽度和高度整数的数组,从中执行放大以满足传递的约束。
by: float
设置“比例倍数”,这将启动通过将图像所有边乘以该值来计算的比例缩放操作。
本作品,包括代码示例,根据 Creative Commons BY-SA 3.0 许可协议获得许可。
目录
    版本