Nginx笔记总结十七:nginx生成缩略图配置(http_image_filter_module)

编译:

./configure --prefix=/usr/local/nginx
--with-http_stub_status_module --with-http_realip_module
--with-http_image_filter_module --with-debug

配置:

location ~* /(\d+).(jpg)$ {
  set $h $arg_h;
  set $w $arg_w;
  image_filter resize $h $w;
}
location ~* /(\d+)_(\d+)x(\d+)\.(jpg)$ {
  if ( -e $document_root/$1.$4) {
    rewrite /(\d+)_(\d+)x(\d+)\.(jpg)$ /$1.$4?h=$2&w=$3 last;
  }
  return 404;
}

 



参数:test 返回是否真的是图片
size:返回图片长短尺寸,返回json格式数据
corp:截取图片的一部分,从左上角开始截取
resize:缩放图片,等比例缩放
优点:根据传入参数即可生成各种比例图片
不占用任何磁盘空间
缺点:消耗cpu,访问量大会给服务器带来极大的负担

posted @ 2017-02-14 10:28  喝杯茶  阅读(1606)  评论(0编辑  收藏  举报