nginx 配置图片自动裁剪

nginx 配置图片自动裁剪

Image Filter module(图像过滤处理模块)

让不同部分能协同工作,nginx需要编译进图像滤波,代理和安全链接三个模块

nginx配置

  location ~* /(.+).(jpg|gif|png)!(d+)x(d+)$ {
        set $w $3;
        set $h $4;

   #    image_filter crop    $w $h;
        image_filter resize  $w $h;
        image_filter_buffer  10M;
        image_filter_jpeg_quality 75;
        try_files /$1.$2  /notfound.jpg;
    }

image_filter resize $w $h; 等比缩放

image_filter crop $w $h; 裁剪到指定尺寸

image_filter_buffer 10M; 图片最大缓存10M 超过的将会异常

image_filter_jpeg_quality $img_quality; 压缩的质量,最高95,一般推荐75就够了

参考:

https://blog.csdn.net/itnobody/article/details/82882636
https://segmentfault.com/a/1190000004604380
https://blog.csdn.net/pushiqiang/article/details/80319745
http://www.ccc5.cc/2104.html?rgvujs=1w1oz2 nginx = webp+php
https://www.cnblogs.com/freeweb/p/5764493.html

nginx如何添加模块

yum安装下的nginx,如何添加模块,和添加第三方模块 (切记不需要重新 make install,只需编译,不需要安装,需要替换可执行文件/usr/sbin/nginx )

https://blog.csdn.net/zzy5066/article/details/81136273 yum安装的nginx如何 新增模块,这篇文章的还不错,值得参考

https://www.jianshu.com/p/a986409e2edd nginx动态新增模块安装

nginx image-filter模块安装
https://blog.csdn.net/revitalizing/article/details/52714198

自动转换图片为webp格式 : 压缩方面比jpg更有优势

快图片加载速度的图片格式。图片压缩体积大约只有JPEG的2/3,并能节省大量的服务器宽带资源和数据空间

http://www.ccc5.cc/2104.html?rgvujs=1w1oz2&bivyty=rj2wu2 Nginx+PHP配置自动转换webp图片,这里面可以参考怎么转发给PHP去处理

https://www.xp.cn/jishu-php-3263.html Nginx rewrite模块深入浅出详解

原文地址:https://www.cnblogs.com/zqsb/p/11383518.html