安装配置
–with-http_image_filter_module
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_image_filter_module
重头戏来了
然后nginx配置文件 比如是一个静态资源服务器加入下面的配置 可以实现图片缩放
其实这个也是要与开发配合着干的,你配置好了,告诉开发这个东西怎么用
image_filter resize 100 100;
image_filter_buffer 10M;
这个就是控制大小的
location ~* /(.*)_(\d+)x(\d+)\.(gif|jpg|jpeg|png|bmp)$ {
add_header Access-Control-Allow-Origin *;
expires 10m;
set $n $1.$4;
set $w $2;
set $h $3;
image_filter resize $w $h;
image_filter_buffer 10M;
rewrite ^/(.*)$ /$n break;
}
location ~* /(.*?)_s\.(gif|jpg|jpeg|png|bmp)$ {
add_header Access-Control-Allow-Origin *;
expires 10m;
set $n $1.$2;
image_filter resize 100 100;
image_filter_buffer 10M;
rewrite ^/(.*)$ /$n break;
}
location ~* /(.*?)_m\.(gif|jpg|jpeg|png|bmp)$ {
add_header Access-Control-Allow-Origin *;
expires 10m;
set $n $1.$2;
image_filter resize 450 450;
image_filter_buffer 10M;
rewrite ^/(.*)$ /$n break;
}
location ~* /(.*?)_l\.(gif|jpg|jpeg|png|bmp)$ {
add_header Access-Control-Allow-Origin *;
expires 10m;
set $n $1.$2;
image_filter resize 800 800;
image_filter_buffer 10M;
rewrite ^/(.*)$ /$n break;
}
然后这个东西用法
这个是第一种方式 图片名称_自定义大小X自定义大小.jpg
http://domian/images/4m_400x400.jpg
第二种用法
这个就是根据上面定义的s m l 来定义尺寸大小的
http://domain/iamges/4m_s.jpg
http://domain/iamges/4m_m.jpg
http://domain/iamges/4m_l.jpg