image_filter

Posts filed under image_filter

使用nginx进行大图等比例缩小并缓存

Filed in 服务器Tags: ,

1、需要image_filter模块,没有的话重新编译nginx,编译参数加上
--with-http_image_filter_module
2、配置文件1(需要使用缩略图的虚拟主机)
location ^~ /images/ {
autoindex off;
alias /path/to/image/file/;
expires 30d;
location ~ ^/images/thumb(100|150|346)/(.*)\.(jpg|png|gif)$
{
alias /path/to/image/cache/thumb$1/$2.$3;
set $image_uri /images/$2.$3?width=$1&height=$1;
set $image_filename thumb$1/$2.$3;
if (!-f $request_filename) {
proxy_pass http://127.0.0.1/$image_uri;
break;
}
proxy_store /path/to/image/cache/$image_filename;
proxy_store_access user:rw group:rw all:r;
proxy_set_header Host 127.0.0.1;
}
}

3、配置文件2(进行缩略图处理的虚拟主机)
server
{
listen 80;
listen [::]:80;
server_name 127.0.0.1;
charset utf-8;

location ~ ^/images/(.*)\.(jpg|png|gif)$
{
alias /path/to/image/file/$1.$2;
set $img_width $arg_width;
set $img_height $arg_height;
image_filter test;
image_filter resize $img_width -;
image_filter_buffer 1M;
image_filter_jpeg_quality 80;
# image_filter_sharpen 50; 0.7.45无该参数
allow 127.0.0.0/8;
deny all;
}
access_log off;
}

4、本例中限定缩小后的宽度为100、150、346之一。

最近评论
Click to view/hide
 
Click to view/hide
2019年十月
« 8月    
 123456
78910111213
14151617181920
21222324252627
28293031  
站点功能
Click to view/hide