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模塊深入淺出詳解