Converter for Media:WordPress网站将图片自动转换为webp格式

介绍一个wordpress插件,可以将上传的图片格式(PNG/JPG等)自动转换为webp格式,这个插件就是Converter for Media。不过这个插件需要修改一下nginx配置,在server里添加下面的配置:

    # BEGIN Converter for Media
    set $ext_avif ".avif";
    if ($http_accept !~* "image/avif") {
        set $ext_avif "";
    }
     
    set $ext_webp ".webp";
    if ($http_accept !~* "image/webp") {
        set $ext_webp "";
    }
     
    location ~* ^/wp-content/(?<path>.+)\.(?<ext>jpe?g|png|gif|webp)$ {
        add_header Vary Accept;
        add_header Cache-Control "private";
        expires 365d;
        try_files
            /wp-content/uploads-webpc/$path.$ext$ext_avif
            /wp-content/uploads-webpc/$path.$ext$ext_webp
            $uri =404;
    }
    # END Converter for Media

而且还有一定的要求,就是要在nginx中include/location之类的代码之前,具体参考下面文章:

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容