First, installation
#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
Second, the configuration
Location ~* (. *\. ( jpg|gif|png))! (.*)! (. *) $ {
set $width $ ;
Set $height $;
Rewrite "(. *\. ( jpg|gif|png)) (. *) $ "$;
}
Location ~*/image/.*\. (jpg|gif|png) $ {
root /home/jfy/web/;
#image_filter off;
#image_filter test;
#image_filter size;
#image_filter rotate;
Image_filter resize $width $height;
#image_filter crop;
Image_filter_buffer 10M;
Image_filter_interlace on;
image_filter_jpeg_quality;
Image_filter_sharpen;
Image_filter_transparency on;
}
Image_filter off;
#关闭模块
image_filter test;
#确保图片是jpeg gif png otherwise return 415 error
image_filter size;
#输出有关图像的json格式: The following shows {"img": {"width": +, "height": the "type": "GIF"}} Error display: {}
image_filter rotate 90|180|270;< c6/> #旋转指定度数的图像, parameters can include variables, either individually or together with resize crop.
image_filter resize width height;
#按比例减少图像到指定大小, the reduction of one can be another with "-" to represent, error 415, parameter values can contain variables, can be used with rotate, then two are in effect together.
image_filter crop width height;
#按比例减少图像比较大的侧面积和另一侧多余的载翦边缘, the others are the same as rotate. Not too understanding
image_filter_buffer 10M;
#设置读取图像缓冲的最大大小, more than 415 errors.
image_filter_interlace on;
#如果启用, the final image will be interleaved. For JPEG, the final image will be in the progressive JPEG format.
image_filter_jpeg_quality;
#设置变换的JPEG图像的期望质量. The acceptable values range from 1 to 100. A smaller value usually means that both the image quality is reduced and the data transferred is reduced, and the recommended maximum value is 95. Parameter values can contain variables.
Image_filter_sharpen;
#增加了最终图像的清晰度. The sharpness percentage can exceed 100. A value of 0 disables sharpening. Parameter values can contain variables.
image_filter_transparency on;
#定义是否应该透明转换的GIF图像或PNG图像与调色板中指定的颜色时, you can keep it. Loss of transparency will result in better image quality. The alpha channel in PNG always retains transparency.
Three, a few rules, may be useful.
Match full station all the end of the picture
---------------------------------------------------------
location ~* \. ( Jpg|gif|png) $ {
image_filter resize;
}
---------------------------------------------------------
match all the pictures of a directory
---------------------------------- -----------------------
location ~*/image/.*\. (jpg|gif|png) $ {
image_filter resize;
}
---------------------------------------------------------
to specify--------------------------------by URL
-------------------------
location ~* (. *\. ( jpg|gif|png))! (.*)! (. *) $ {
set $width $ ;
Set $height $;
Rewrite "(. *\. ( jpg|gif|png)) (. *) $ "$;
}
Location ~*/image/.*\. (jpg|gif|png) $ {
Image_filter resize $width $height;
}
---------------------------------------------------------
http://172.16.18.114/image/girl.jpg!300!200
automatically scales the original image to the size of the 300*200
Detailed effects can be found in: http://cwtea.blog.51cto.com/blog/4500217/1333142