【问题标题】:Does liip_imagine convert jpeg/jpg/png file to webp? - symfony php 7.4.9liip_imagine 是否将 jpeg/jpg/png 文件转换为 webp? - symfony php 7.4.9
【发布时间】:2021-10-05 09:21:48
【问题描述】:

所以我想将我项目中的现有图像从 jpeg/jpg/png 转换为 .webp 扩展名。我已经读过使用想象它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 并再次上传还是什么?

【问题讨论】:

    标签: php symfony png webp liipimaginebundle


    【解决方案1】:

    你快到了!您错过了路径中的 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>
    

    【讨论】:

    • 会发生什么?
    • 它仍在设置 png 文件的路径
    • 是否应该创建新文件,例如 '/path/to/image.png.webp' 还是什么?
    • 我的回答对您有帮助吗?如果是这样,请考虑支持/接受我的回答。如果没有,请告诉我,以便我改进答案!
    • 所以你在发现你有另一个问题后不接受我的回答?
    猜你喜欢
    • 2022-11-30
    • 2023-02-24
    • 2016-07-22
    • 1970-01-01
    • 2012-12-22
    • 2020-01-05
    • 2011-09-30
    • 2023-02-06
    • 2020-04-24
    相关资源
    最近更新 更多