非常教程

Nginx参考手册

ngx_http_image_filter_module

ngx_http_image_filter_module

  • 示例配置
  • 指令
  • image_filter
  • image_filter_buffer
  • image_filter_interlace
  • image_filter_jpeg_quality
  • image_filter_sharpen
  • image_filter_transparency
  • image_filter_webp_quality

ngx_http_image_filter_module模块(0.7.54+)是一种过滤器,可以转换JPEG,GIF,PNG和WebP格式的图像。

该模块不是默认生成的,它应该使用--with-http_image_filter_module配置参数启用。

该模块使用libgd库。建议使用库的最新版本。WebP格式支持出现在版本1.11.6中。要以这种格式转换图像,libgd必须使用WebP支持编译库。

示例配置

location /img/ {
    proxy_pass   http://backend;
    image_filter resize 150 100;
    image_filter rotate 90;
    error_page   415 = /empty;
}

location = /empty {
    empty_gif;
}

指令

句法:

image_filter off; image_filter test; image_filter size; image_filter rotate 90 | 180 | 270; image_filter调整宽度高度; image_filter裁剪宽度高度;

默认:

image_filter off;

语境:

位置

设置要在图像上执行的转换类型:

off关闭周围位置的模块处理。test确保响应是JPEG,GIF,PNG或WebP格式的图像。否则,返回415(不支持的媒体类型)错误。size以JSON格式输出关于图像的信息,例如:

{ "img" : { "width": 100, "height": 100, "type": "gif" } }

出现错误时,输出如下所示:

{}

rotate90| 180| 270将图像逆时针旋转指定的度数。参数值可以包含变量。这种模式可以单独使用,也可以resizecrop转换一起使用。resizewidthheight按比例将图像缩小至指定尺寸。要减少一个维度,可以将另一个维度指定为“ -”。如果发生错误,服务器将返回代码415(不支持的介质类型)。参数值可以包含变量。与rotate参数一起使用时,旋转发生缩小之后cropwidthheight按比例将图像缩小到较大的一侧,并在另一侧产生无关边缘。为了仅减少一个维度,可以将另一个维度指定为“-”。如果发生错误,服务器将返回代码415(不支持的介质类型)。参数值可以包含变量。当与rotate参数一起使用时,旋转发生缩减之前

句法:

image_filter_buffer大小;

默认:

image_filter_buffer 1M;

语境:

http,服务器,位置

设置用于读取图像的缓冲区的最大大小。当超过大小时,服务器返回错误415(不支持的介质类型)。

句法:

image_filter_interlace开启 | 关闭;

默认:

image_filter_interlace off;

语境:

http,服务器,位置

如果启用,最终图像将交错。对于JPEG,最终图像将采用“逐行JPEG”格式。

句法:

image_filter_jpeg_quality质量;

默认:

image_filter_jpeg_quality 75;

语境:

http,服务器,位置

设置所需quality的转换后的JPEG图像。可接受的值在1到100的范围内。较小的值通常意味着较低的图像质量和较少的数据传输。最大推荐值是95.参数值可以包含变量。

句法:

image_filter_sharpen百分比;

默认:

image_filter_sharpen 0;

语境:

http,服务器,位置

增加最终图像的清晰度。锐度百分比可以超过100.零值禁用锐化。参数值可以包含变量。

句法:

image_filter_transparency 开启 | 关闭;

默认:

image_filter_transparency 开启;

语境:

http,服务器,位置

定义在使用调色板指定的颜色转换GIF图像或PNG图像时是否应保留透明度。透明度的降低会导致质量更好的图像。PNG中的alpha通道透明度始终保留。

句法:

image_filter_webp_quality质量;

默认:

image_filter_webp_quality 80;

语境:

http,服务器,位置

设置所需quality的转换后的WebP图像。可接受的值在1到100的范围内。较小的值通常意味着较低的图像质量和较少的数据传输。参数值可以包含变量。

ngx_http_image_filter_module
Nginx

Nginx是一款轻量级的 Web 服务器/反向代理服务器及电子邮件代理服务器,可在 BSD-like 协议下发行。其特点是占有内存少,并发能力强。

主页 https://nginx.org/
源码 http://hg.nginx.org/nginx
发布版本 1.13.6

Nginx目录

1.指南 | Guides
2.核心 | Core
3.ngx_google_perftools_module
4.ngx_http_access_module
5.ngx_http_addition_module
6.ngx_http_api_module
7.ngx_http_auth_basic_module
8.ngx_http_auth_jwt_module
9.ngx_http_auth_request_module
10.ngx_http_autoindex_module
11.ngx_http_browser_module
12.ngx_http_charset_module
13.ngx_http_core_module
14.ngx_http_dav_module
15.ngx_http_empty_gif_module
16.ngx_http_f4f_module
17.ngx_http_fastcgi_module
18.ngx_http_flv_module
19.ngx_http_geoip_module
20.ngx_http_geo_module
21.ngx_http_gunzip_module
22.ngx_http_gzip_module
23.ngx_http_gzip_static_module
24.ngx_http_headers_module
25.ngx_http_hls_module
26.ngx_http_image_filter_module
27.ngx_http_index_module
28.ngx_http_js_module
29.ngx_http_keyval_module
30.ngx_http_limit_conn_module
31.ngx_http_limit_req_module
32.ngx_http_log_module
33.ngx_http_map_module
34.ngx_http_memcached_module
35.ngx_http_mirror_module
36.ngx_http_mp4_module
37.ngx_http_perl_module
38.ngx_http_proxy_module
39.ngx_http_random_index_module
40.ngx_http_realip_module
41.ngx_http_referer_module
42.ngx_http_rewrite_module
43.ngx_http_scgi_module
44.ngx_http_secure_link_module
45.ngx_http_session_log_module
46.ngx_http_slice_module
47.ngx_http_spdy_module
48.ngx_http_split_clients_module
49.ngx_http_ssi_module
50.ngx_http_ssl_module
51.ngx_http_status_module
52.ngx_http_stub_status_module
53.ngx_http_sub_module
54.ngx_http_upstream_conf_module
55.ngx_http_upstream_hc_module
56.ngx_http_upstream_module
57.ngx_http_userid_module
58.ngx_http_uwsgi_module
59.ngx_http_v2_module
60.ngx_http_xslt_module
61.ngx_mail_auth_http_module
62.ngx_mail_core_module
63.ngx_mail_imap_module
64.ngx_mail_pop3_module
65.ngx_mail_proxy_module
66.ngx_mail_smtp_module
67.ngx_mail_ssl_module
68.ngx_stream_access_module
69.ngx_stream_core_module
70.ngx_stream_geoip_module
71.ngx_stream_geo_module
72.ngx_stream_js_module
73.ngx_stream_limit_conn_module
74.ngx_stream_log_module
75.ngx_stream_map_module
76.ngx_stream_proxy_module
77.ngx_stream_realip_module
78.ngx_stream_return_module
79.ngx_stream_split_clients_module
80.ngx_stream_ssl_module
81.ngx_stream_ssl_preread_module
82.ngx_stream_upstream_hc_module
83.ngx_stream_upstream_module