FormatExtensionResolver
FormatExtensionResolver
不能单独使用。相反,它是另一个解析器的“装饰器”。它添加了在过滤器转换图像格式时设置正确文件扩展名的能力。
配置
要使用此缓存解析器,您必须首先定义它将装饰的缓存解析器。在此示例中,我们将使用 Web Path Resolver。
接下来,我们需要为此缓存解析器定义一个服务,并将要装饰的 web path 缓存解析器服务注入进去。
1 2 3 4 5 6 7 8 9 10
# app/config/services.yml
services:
acme.imagine.cache.format_extension:
class: Liip\ImagineBundle\Imagine\Cache\Resolver\FormatExtensionResolver
arguments:
- "@acme.imagine.cache.resolver.web_path"
- "@liip_imagine.filter.configuration"
tags:
- { name: "liip_imagine.cache.resolver", resolver: "format_extension" }
通过此配置,格式扩展名解析器将重写扩展名以匹配过滤器格式。例如,如果您有源图像 image.png
并且您应用了格式为 jpg
的过滤器,您将获得 jpeg 图像 image.jpg
。
用法
配置 FormatExtensionResolver
后,您可以将其设置为 LiipImagineBundle
的默认缓存解析器,使用以下配置。
1 2 3 4
# app/config/config.yml
liip_imagine:
cache: format_extension
在特定过滤器上的用法
或者,您可以将 FormatExtensionResolver
设置为特定过滤器集的缓存解析器,使用以下配置。
1 2 3 4 5 6 7 8 9
# app/config/config.yml
liip_imagine:
filter_sets:
cache: ~
my_thumb:
cache: format_extension
filters:
# the filter list
这项工作,包括代码示例,根据 Creative Commons BY-SA 3.0 许可协议获得许可。