在此之前需要安裝
ngx_http_image_filter_module
,如果是采用的Docker的話可以看看我歷史文章。
然后修改配置文件,增加幾個location模塊,配置如下,僅供參考👇
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
location ~* (.*)_(\d+)x(\d+)\.(JPG|jpeg|jpg|gif|png|PNG)$ {
set $img_width $2;
set $img_height $3;
image_filter resize $img_width $img_height;
image_filter_buffer 10M;
rewrite ^(.*)_(\d+)x(\d+).(JPG|jpeg|jpg|gif|png|PNG)$ /$1.$4 break;
proxy_pass http://127.0.0.1:9999;
}
location ~* (.*)_(\d+)x(\d+)_(\d+)\.(JPG|jpeg|jpg|gif|png|PNG)$ {
set $img_width $2;
set $img_height $3;
set $img_quality $4;
rewrite ^(.*)_(\d+)x(\d+)_(\d+).(JPG|jpeg|jpg|gif|png|PNG)$ /$1.$5 break;
image_filter resize $img_width $img_height;
image_filter_buffer 10M;
image_filter_jpeg_quality $img_quality;
proxy_pass http://127.0.0.1:9999;
}
location ~* (.*).(JPG|jpeg|jpg|gif|png|PNG)$ {
proxy_pass http://127.0.0.1:9999;
}
最后訪問格式如下:
裁剪100x100:http://xxx.com/test_100x100.jpg
裁剪200x200兼調整質量60:http://xxx.com/test_200x200_60.jpg
大概就是這個意思吧。僅供參考,如有大神希望指出問題所在,我們大家一起學習一下。
也當作自己的一個記錄,怕以后又忘記了。