http_image_filter_module是nginx提供的集成图片处理模块,支持nginx-0.7.54以后的版本,在网站访问量不是很高磁盘有限不想生成多余的图片文件的前提下可,就可以用它实时缩放图片,旋转图片,验证图片有效性以及获取图片宽高以及图片类型信息,由于是即时计算的结果,所以网站访问量大的话,不建议使用。或者nginx前面再加一层缓存。
安装还是很简单的,默认HttpImageFilterModule模块是不会编译进nginx的,所以要在configure时候指定
./configure --prefix=/usr/local/nginx --with-http_image_filter_module
HttpImageFilterModule模块需要依赖gd-devel的支持,可以使用yum或apt-get方便地安装,如果未安装回报“/configure: error: the HTTP image filter module requires the GD library.”错误
centos办法
yum install gd-devel
ubuntu办法
apt-get install libgd2-xpm libgd2-xpm-dev
make && make install后就可以进行配置了,做最简单的配置,先让模块可以跑起来
location / {
root html;
index index.html index.htm;
}
location ~ /image/.*\.jpg$ {
#proxy_pass http://192.168.1.1;
#rewrite "/image/(.*\.jpg)$" /img/$1 break;
image_filter resize 100 100;
error_page 415 = /empty;
}
最后开启nginx,这样访问/image/目录下的图片,都会按照高度最高100并且宽度最高100按照原图比例进行截取出来,并输出给浏览器。当然也可以开启重写去读取本机另一个目录下源文件;如果不在一台机器上就可以开启proxy_pass,并加上重写即可。
http_image_filter_module支持5种指令:
image_filter:测试图片文件合法性(image_filter test);3个角度旋转图片(image_filter rotate 90 | 180 | 270);以json格式输出图片宽度、高度、类型(image_filter size);最小边缩小图片保持图片完整性(resize width height);以及最大边缩放图片后截取多余的部分(image_filter crop [width] [height]);
image_filter_jpeg_quality:设置jpeg图片的压缩质量比例(官方最高建议设置到95,但平时75就可以了);
image_filter_buffer:限制图片最大读取大小,默认为1M;
image_filter_transparency:用来禁用gif和palette-based的png图片的透明度,以此来提高图片质量。
image_filter_sharpen:暂时未知。
其他用法
location ~* /(\w+)\.(jpg)$ {
set $h $arg_h; #获取参数h的值
set $w $arg_w; #获取参数w的值
#image filter crop $h $w;
image_filter resize $h $w; #根据给定的长宽生成缩略图
}
location ~* /(\w+)_(\d+)×(\d+)\.(jpg)$ {
if (-e $document_root/$1.$4) {
rewrite /(\w+)_(\d+)×(\d+)\.(jpg)$ /$1.$4?h=$2&w=$3 last;
}
return 404;
}
在nginx的html目录下,上传图片123.jpg
通过浏览器访问
http://192.168.56.2:8080/123_800×800.jpg
分享到:
相关推荐
已经添加了http_image_filter_module模块的nginx版本,包含了libgd.dll,nginx版本1.15.9,windows64位版本
这里以安装第三方ngx_http_google_filter_module模块为例 nginx的模块是需要重新编译nginx,而不是像apache一样配置文件引用.so 1. 下载第三方扩展模块ngx_http_google_filter_module # cd /data/software/ # git...
使用参考地址:https://blog.csdn.net/qq_36749924/article/details/130992813 已经添加了http_image_filter_module模块的nginx版本,包含了libgd.dll,nginx版本1.15.9,windows64位版本
Nginx所需环境的安装,及nginx安装,nginx相关功能开启,后端节点健康检查插件安装,静态资源缓存插件,缩略图插件安装等。
nginx 的依赖ngx_http_image_filter_module ngx_let_module ngx_eval_module 配置nginx ./configure --with-http_image_filter_module --add-module=/path/to/ngx_let_module --add-module=/path/to/ngx_eval_module...
http_image_filter_module是nginx提供的集成图片处理模块,支持nginx-0.7.54以后的版本,在网站访问量不是很高磁盘有限不想生成多余的图片文件的前提下可,就可以用它实时缩放图片,旋转图片,验证图片有效性以及...
8、./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/home/tar/pcre-8.35 --with-http_realip_module --with-...
./configure --prefix=/Data/apps/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-stream 注意 1.因为mysql默认使用了3306端口...
相信大家都知道利用yum安装nginx 非常方便,但是有些插件并不会默认安装,比如 http_image_filter_module, 因此我们需要编译安装 nginx,已达到我们的目的。下面来看看详细的方法吧。 安装依赖 yum install -y ...
redhat 6.4 安装nginx可能会报错./configure: error: the HTTP image filter module requires the GD library. You can either do not enable the module or install the libraries. 此时需要安装gd gd-devel,需要...
除错启动本地测试服务器( ): CW=0 go run main.goSSO登录(已弃用) 提交:b0e04f85b21f480cd0fb1e5c2ebd084a0f7ad37a安装nginx-module-image-filter(Debian) curl -O ...