nginx图片过滤模块和图片缩放

安装配置
–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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值