博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Nginx之http_image_filter_module模块使用
阅读量:7174 次
发布时间:2019-06-29

本文共 3054 字,大约阅读时间需要 10 分钟。

原文:http://blog.csdn.net/jiao_fuyou/article/details/37598441

一、安装

#yum install gd-devel  #  #./configure --prefix=/usr/local/nginx     \  #  --with-debug                            \  #  --with-http_stub_status_module          \  #  --with-http_ssl_module                  \  #  --with-http_realip_module               \  #  --with-http_image_filter_module         \  #  --with-pcre=../pcre-8.21                \  #  --add-module=../ngx_devel_kit-0.2.19    \  #  --add-module=../lua-nginx-module-0.9.8  \  #  --add-module=../echo-nginx-module       \  #  --add-module=../redis2-nginx-module     \  #  --add-module=../set-misc-nginx-module

 

二、配置

location ~* (.*\.(jpg|gif|png))!(.*)!(.*)$ {      set $width   $3;      set $height  $4;      rewrite "(.*\.(jpg|gif|png))(.*)$" $1;  }    location ~* /image/.*\.(jpg|gif|png)$ {      root   /home/jfy/web/;      #image_filter off;      #image_filter test;      #image_filter size;      #image_filter rotate 90;      image_filter resize $width $height;      #image_filter crop 300 200;      image_filter_buffer 10M;      image_filter_interlace on;      image_filter_jpeg_quality 95;      image_filter_sharpen 100;      image_filter_transparency on;  }

 

说明

image_filter off;  #关闭模块    image_filter test;  #确保图片是jpeg gif png否则返415错误    image_filter size;  #输出有关图像的json格式:如下显示{ "img" : { "width": 100, "height": 100, "type": "gif" } } 出错显示:{}    image_filter rotate 90|180|270;  #旋转指定度数的图像,参数可以包括变量,单独或一起与resize crop一起使用。    image_filter resize width height;  #按比例减少图像到指定大小,公减少一个可以另一个用"-"来表示,出错415,参数值可包含变量,可以与rotate一起使用,则两个一起生效。    image_filter crop width height;  #按比例减少图像比较大的侧面积和另一侧多余的载翦边缘,其它和rotate一样。没太理解    image_filter_buffer 10M;  #设置读取图像缓冲的最大大小,超过则415错误。    image_filter_interlace on;  #如果启用,最终的图像将被交错。对于JPEG,最终的图像将在“渐进式JPEG”格式。    image_filter_jpeg_quality 95;  #设置变换的JPEG图像的期望质量。可接受的值是从1到100的范围内。较小的值通常意味着既降低图像质量,减少传输数据,推荐的最大值为95。参数值可以包含变量。    image_filter_sharpen 100;  #增加了最终图像的清晰度。锐度百分比可以超过100。零值将禁用锐化。参数值可以包含变量。    image_filter_transparency on;  #定义是否应该透明转换的GIF图像或PNG图像与调色板中指定的颜色时,可以保留。透明度的损失将导致更好的图像质量。在PNG的Alpha通道总是保留透明度。

 

四、几个规则,可能有用。

匹配全站所有的结尾图片  ---------------------------------------------------------          location ~* \.(jpg|gif|png)$ {              image_filter resize 500 500;          }  ---------------------------------------------------------    匹配某个目录所有图片  ---------------------------------------------------------          location ~* /image/.*\.(jpg|gif|png)$ {              image_filter resize 500 500;          }  ---------------------------------------------------------    再比如用url来指定  ---------------------------------------------------------          location ~* (.*\.(jpg|gif|png))!(.*)!(.*)$ {              set $width      $3;              set $height     $4;              rewrite "(.*\.(jpg|gif|png))(.*)$" $1;          }                    location ~* /image/.*\.(jpg|gif|png)$ {              image_filter resize $width $height;          }  ---------------------------------------------------------  http://172.16.18.114/image/girl.jpg!300!200  自动将原图缩放为300*200的尺寸

 

详细效果可参见:

 

你可能感兴趣的文章
萧墙HTML5手机发展之路(53)——jQueryMobile页面之间的参数传递
查看>>
社会保障系列1《介绍》
查看>>
Windows10开发手记-Windows App Certification Kit使用教程
查看>>
iOS开发网络篇—NSURLConnection基本使用(二)
查看>>
事件引入和本质
查看>>
Java:IO流的综合用法(从键盘录入数据并打印在控制台上)
查看>>
只允许输入数字和小数点
查看>>
快速排序(五)
查看>>
ASP.NET MVC 中将FormCollection与实体间转换方法 (转)
查看>>
至linuxNIC添加多个IP
查看>>
WebKit.net最简单使用方法
查看>>
CDN技术
查看>>
开发人员看测试之细说JBehave
查看>>
实验记录贴 —— 账号同步实验 RTX 和 LDAP(AD域)
查看>>
【C语言】reverse_string(char * string)(递归)
查看>>
SQLHlper意识
查看>>
POJ2195 Going Home 【最小费用流】+【最佳匹配图二部】
查看>>
Swift - 给表格UITableView添加索引功能(快速定位)
查看>>
fixed的left:50%,漂浮
查看>>
浅谈JAVA集合框架
查看>>