所以我想将项目中的现有图像从 jpeg/jpg/png 转换为 .webp 扩展名。我读过使用 Imagine https://github.com/liip/LiipImagineBundle/pull/1307 , 但 它不起作用,我的 liip_imagine 看起来像这样:
liip_imagine:
driver: "imagick"
default_filter_set_settings:
format: webp
webp:
generate: true
quality: 80
cache: ~
data_loader: ~
post_processors: [ ]
resolvers:
profile_photos:
web_path:
# use %kernel.project_dir%/web for Symfony prior to 4.0.0
web_root: "%kernel.project_dir%/web"
cache_prefix: "cache"
filter_sets:
cache: ~
my_thumbnail:
quality: 80
filters:
thumbnail: { mode: inset }
post_processors:
optipng:
strip_all: true
level: 3
my_thumbnail_webp:
format: webp
quality: 80
filters:
thumbnail: { mode: inset }
post_processors:
optipng:
strip_all: true
level: 3
然后我有这个:
<picture>
<source srcset="{{ '/path/to/image.png' | imagine_filter('my_thumbnail_webp') }}" type="image/webp">
<source srcset="{{ '/path/to/image.png' | imagine_filter('my_thumbnail') }}" type="image/png">
<img src="{{ '/path/to/image.png' | imagine_filter('my_thumbnail') }}">
</picture>
但它不起作用!我该如何解决我的问题? 在网站上我仍然有/path/to/image.png - 所以它不会改变任何东西,我想要/path/to/image.png.webp 我应该将项目中的每个 img 文件转换为 webp 并再次上传还是什么?
最佳答案
你就快到了!您错过了路径中的 asset
方法:
<img src="{{ asset('/relative/path/to/image.jpg') | imagine_filter('my_thumb') }}" />
所以应该是:
<picture>
<source srcset="{{ asset'/path/to/image.png') | imagine_filter('my_thumbnail_webp') }}" type="image/webp">
<source srcset="{{ asset('/path/to/image.png') | imagine_filter('my_thumbnail') }}" type="image/png">
<img src="{{ asset('/path/to/image.png') | imagine_filter('my_thumbnail') }}">
</picture>
关于php - liip_imagine 是否将 jpeg/jpg/png 文件转换为 webp? - symfony PHP 7.4.9,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68580647/