Opti PNG
OptiPngPostProcessor
是一个内置的后处理器,它对 PNG 编码的图像执行多项无损优化。
要将此后处理器添加到缩略图使用示例中创建的过滤器集中,请使用
1 2 3 4 5 6 7 8 9 10
# app/config/config.yml
liip_imagine:
filter_sets:
my_thumb:
filters:
thumbnail: { size: [120, 90], mode: outbound }
background: { size: [124, 94], position: center, color: '#000' }
post_processors:
optipng: { strip_all: true, level: 5 }
此配置启用元数据剥离,并将结果图像二进制文件的最大优化因子设置为 5。
注意
默认可执行文件路径为 /usr/bin/optipng
。如果安装在系统中的其他位置,您必须相应地设置 liip_imagine.optipng.binary
参数。
1 2 3 4
# app/config/config.yml
parameters:
liip_imagine.optipng.binary: /your/custom/path/to/optipng
选项
- level:
int
- 设置图像优化级别。有效值是介于
0
和7
之间的整数。 - snip:
bool
- 当遇到多图像(例如,动画图像)时,这将导致保留其中一个图像并删除其他图像。根据输入格式,这可能是第一个或最相关的(例如,最大的)图像。
- strip_all:
bool
(已弃用) - 删除所有注释、EXIF 标记和其他图像元数据。
- level:
int
- 设置图像优化因子,从 0 到 7。
- strip:
bool|string
- 当设置为
true
时,所有额外的图像头,例如其注释、EXIF 标记和其他元数据,都将被删除。 同样,字符串值all
也删除所有额外的元数据。 - preserve_attributes:
bool
- 在适用/可能的情况下,保留文件属性(时间戳、文件访问权限等)。
- interlace_type:
int
- 设置用于输出文件的隔行扫描类型。 当设置为
0
时,输出图像将是非隔行扫描的。 当设置为1
时,输出图像将使用 Adam7 方法进行隔行扫描。 如果未设置,则输出将具有与原始输入相同的隔行扫描类型。 - no_bit_depth_reductions:
bool
- 禁用任何位深度缩减优化。
- no_color_type_reductions:
bool
- 禁用任何颜色类型缩减优化。
- no_palette_reductions:
bool
- 禁用任何颜色调色板缩减优化。
- no_reductions:
bool
- 禁用任何无损缩减优化,启用
no_bit_depth_reductions
、no_color_type_reductions
和no_palette_reductions
。
参数
- liip_imagine.optipng.stripAll:
bool
- 从图像二进制文件中删除所有注释、EXIF 标记和其他元数据。
- liip_imagine.optipng.level:
int
- 设置图像优化因子。 默认为
7
。 - liip_imagine.optipng.binary:
string
- 设置
optipng
可执行文件的位置。 默认为/usr/bin/optipng
。 - liip_imagine.optipng.tempDir:
string
- 设置存储临时文件的目录。
提示
liip_imagine.optipng.tempDir
的值可以设置为受支持操作系统上的内存挂载点,例如 Linux 上的 /run/shm
。 这将减少磁盘负载并可能提高性能。
这项工作,包括代码示例,均根据 Creative Commons BY-SA 3.0 许可获得许可。