kyujhgfd 发表于 2017-11-1 08:51:04

ngx_http_image_filter_module模块安装配置

测试环境:Tengine 2.1,centos6.9
官网有说明,支持动态共享加载模块
编译配置,指定加载为动态共享模块:

1
2
3
wget http://tengine.taobao.org/download/tengine-2.1.0.tar.gz
./configure--prefix=/App/nginx --with-http_image_filter_module=shared
make




将 objs/modules下面的模块复制到nginx工作目录modules下,注意文件属性
添加模块加载段相关配置:

1
2
3
4
5
6
7
8
worker_processes1;
dso {
   load ngx_http_lua_module.so;
   load ngx_http_memcached_module.so;
}
events {
    worker_connections1024;
}




我测试,2.1编译的模块和2.2编译的模块不能交叉使用

图片转换,支持JPEG, GIF, PNG, and WebP格式
依赖库:libgd(gd-devel),yum安装即可

示例配置:

1
2
3
4
5
6
7
8
9
location /img/ {
    proxy_pass   http://backend;
    image_filter resize 150 100;
    image_filter rotate 90;
    error_page   415 = /empty;
}
location = /empty {
    empty_gif;
}





以下指令在location段配置:
image_filter off;关闭此区域处理器
image_filter test;确保图片类型是JPEG, GIF, PNG, or WebP,否则返回415错误
image_filter size;以JSON格式输出有关图像的信息
eg:
    { "img" : { "width": 100, "height": 100, "type": "gif" } }
    error:
    {}
image_filter rotate 90 | 180 | 270;
    规定度数逆时针旋转,参数可包含变量,可以单独使用,也可以和resize/crop一起
image_filter resize width height;
    按指定大小裁剪(缩放效果),width和height可以只设置一个维度,另一个用 - 代替,出错             会返回415错误(不支持的媒体类型)
    (注:测试以较小边的尺寸为标准缩放)
    参数可以包含变量,与rotate一起使用时,rotate放在resize之后。
image_filter crop width height;
    根据设置按比例得减小图像(以最大边缩放),然后裁剪,裁剪为设置一样大小的图片

以下指令可以在http,server,location段配置:
image_filter_buffer 1M;默认1M
    设置读取图片的最大buffer,超出大小会返回415错误
image_filter_interlace off;
    If enabled, final images will be interlaced交错. For JPEG, final images will be in                  “progressive JPEG” format。
image_filter_jpeg_quality 75;
    传输质量,范围1--100,建议最大95,参数可包含变量
image_filter_sharpen 0
    增加图像锐度,可以超过100%,0表示关闭,参数可包含变量
image_filter_transparency on;
    当用指定的调色板颜色转换gif/png图片时是否保留透明度,减小透明度图像质量更高
image_filter_webp_quality 80;
    WebP images的质量

页: [1]
查看完整版本: ngx_http_image_filter_module模块安装配置