通用过滤器
背景
内置的 background
过滤器执行图层转换(包括创建和合并图层操作)。此过滤器公开了许多 背景选项,可用于配置其行为。
配置示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
# app/config/config.yml
liip_imagine:
filter_sets:
# name our filter set "my_background_filter"
my_background_filter:
filters:
# use and setup the "background" filter
background:
# set the background color to #00ffff
color: '#00ffff'
# set a size different from the input image
size: [1026, 684]
# center input image on the newly created background
position: center
注意
背景颜色仅在透明图像部分(如果有)中可见,除非提供了 size 选项,在这种情况下,将创建一个新图像,并且输入图像根据 position 选项放置在顶部。
背景选项
- color:
string
- 设置背景颜色 HEX 值。默认颜色为白色 (
#fff
)。 - size:
int[]
- 将生成的背景大小设置为整数数组,其中包含宽度和高度值作为尺寸。
- position:
string
- 设置输入图像在新创建的背景图像上的位置。有效值:
topleft
、top
、topright
、left
、center
、right
、bottomleft
、bottom
和bottomright
。 - transparency:
integer
- 设置背景 alpha 值。该值应在 0(不透明)- 100(完全透明)的范围内。
灰度
内置的 grayscale
过滤器执行颜色转换(包括灰度值计算)。此过滤器不公开任何可用于配置其行为的选项。
配置示例
1 2 3 4 5 6 7 8 9 10 11
# app/config/config.yml
liip_imagine:
filter_sets:
# name our filter set "my_grayscale_filter"
my_grayscale_filter:
filters:
# use and setup the "grayscale" filter
grayscale: ~
隔行扫描
内置的 interlace
过滤器执行文件转换(包括修改编码方法)。此过滤器公开了许多 隔行扫描选项,可用于配置其行为。
配置示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# app/config/config.yml
liip_imagine:
filter_sets:
# name our filter set "my_interlace_filter"
my_interlace_filter:
filters:
# use and setup the "interlace" filter
interlace:
# set the interlace mode to line
mode: line
隔行扫描选项
- mode:
string
- 设置用于编码文件的隔行扫描模式。有效值:
none
、line
、plane
和partition
。
重采样
内置的 resample
过滤器提供重采样转换,允许您更改图像的分辨率。此过滤器公开了许多 重采样选项,可用于配置其行为。
提示
重采样更改图像的图像分辨率(也称为“像素密度”),当您需要根据用户的屏幕密度呈现不同版本的图像时,此功能非常有用。例如,您可能需要提供“普通”和“视网膜”变体。
“分辨率”的使用不应与“尺寸”混淆。此过滤器不影响图像的尺寸,仅影响像素密度。
配置示例
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
# app/config/config.yml
liip_imagine:
filter_sets:
# name our filter set "my_resample_filter"
my_resample_filter:
filters:
# use and setup the "resample" filter
resample:
# set the unit to use for pixel density
unit: ppi
# set the horizontal pixel density
x: 72
# set the vertical pixel density
y: 72
# set the resampling filter
filter: lanczos
# set the temporary path to use for resampling work
tmp_dir: /my/custom/temporary/directory/path
重采样选项
- unit:
string
- 设置用于像素密度的单位,可以是“每英寸像素”或“每厘米像素”。有效值:
ppi
和ppc
。 - x:
int|float
- 设置要将图像重采样到的水平 (x) 像素密度。
- y:
int|float
- 设置要将图像重采样到的垂直 (y) 像素密度。
- filter:
string
- 设置在重采样操作期间使用的可选过滤器。它必须是一个字符串,可以解析为
Imagine\Image\ImageInterface
的常量(您可以省略FILTER_
前缀)或有效的完全限定常量。默认情况下,它设置为FILTER_UNDEFINED
。 - tmp_dir:
string
- 设置可选的临时工作目录。此过滤器需要一个临时位置来保存和读回图像二进制文件,因为这些操作是重采样图像所必需的。默认情况下,它设置为
sys_get_temp_dir()
函数的值。
去除
内置的 strip
过滤器执行文件转换(包括元数据删除)。此过滤器不公开任何可用于配置其行为的选项。
配置示例
1 2 3 4 5 6 7 8 9 10 11
# app/config/config.yml
liip_imagine:
filter_sets:
# name our filter set "my_strip_filter"
my_strip_filter:
filters:
# use and setup the "strip" filter
strip: ~
水印
内置的 watermark_image
过滤器向现有图像添加水印(包括创建和合并图像操作)。此过滤器公开了许多 水印选项,可用于配置其行为。
配置示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
# app/config/config.yml
liip_imagine:
filter_sets:
# name our filter set "my_watermark_filter"
my_watermark_filter:
filters:
# use and setup the "watermark_image" filter
watermark_image:
# path to the watermark file (prepended with "%kernel.project_dir%")
image: assets/watermark.png
# size of the water mark relative to the input image
size: 0.5
# set the position of the watermark
position: center
水印选项
- image:
string
- 设置水印图像的位置。此选项的值前缀为
%kernel.project_dir%
参数的已解析值。 - size:
float
- 将水印的大小设置为相对于原始输入图像的相对比率。
- position:
string
-
设置水印在输入图像上的位置。有效值:
topleft
、top
、topright
、left
、center
、right
、bottomleft
、bottom
、bottomright
和multiple
。当使用
multiple
时,水印会尽可能频繁地粘贴到图像上。
注意
此过滤器的 position 选项和 ordering 非常重要。例如,在此过滤器之后调用 crop
可能会无意中从最终图像中完全删除水印。