Nginx中文文档
DocsHome
  • 贡献导引
  • 介绍
    • 安装 nginx
    • 从源码构建 nginx
    • 初学者指南
    • 管理指南
    • 控制 nginx
    • 连接处理方式
    • 设置哈希
    • 调试日志
    • 记录日志到 syslog
    • 配置文件度量单位
    • 命令行参数
    • Windows 下的 nginx
    • QUIC 和 HTTP/3 支持
    • nginx 如何处理请求
    • 服务器名称
    • 使用 nginx 作为 HTTP 负载均衡器
    • 配置 HTTPS 服务器
    • nginx 如何处理 TCP/UDP 会话
    • 关于 nginScript
  • 其他
    • Linux 软件包
  • How-To
    • 在 Win32 平台上使用 Visual C 构建 nginx
    • 设置 Amazon EC2 的 Nginx Plus 环境
    • 使用 DTrace pid 提供程序调试 nginx
    • 转换重写规则
    • WebSocket 代理
  • 开发
    • 贡献指南
    • 开发指南
  • 模块参考
  • 核心功能
    • HTTP
      • ngx_http_core_module
      • ngx_http_access_module
      • ngx_http_addition_module
      • ngx_http_api_module
      • ngx_http_auth_basic_module
      • ngx_http_auth_jwt_module
      • ngx_http_auth_request_module
      • ngx_http_autoindex_module
      • ngx_http_browser_module
      • ngx_http_charset_module
      • ngx_http_dav_module
      • ngx_http_empty_gif_module
      • ngx_http_f4f_module
      • ngx_http_fastcgi_module
      • ngx_http_flv_module
      • ngx_http_geo_module
      • ngx_http_geoip_module
      • ngx_http_grpc_module
      • ngx_http_gunzip_module
      • ngx_http_gzip_module
      • ngx_http_gzip_static_module
      • ngx_http_headers_module
      • ngx_http_hls_module
      • ngx_http_image_filter_module
      • ngx_http_index_module
      • ngx_http_js_module
      • ngx_http_keyval_module
      • ngx_http_limit_conn_module
      • ngx_http_limit_req_module
      • ngx_http_log_module
      • ngx_http_map_module
      • ngx_http_memcached_module
      • ngx_http_mirror_module
      • ngx_http_mp4_module
      • ngx_http_perl_module
      • ngx_http_proxy_module
      • ngx_http_random_index_module
      • ngx_http_realip_module
      • ngx_http_referer_module
      • ngx_http_rewrite_module
      • ngx_http_scgi_module
      • ngx_http_secure_link_module
      • ngx_http_session_log_module
      • ngx_http_slice_module
      • ngx_http_spdy_module(过时)
      • ngx_http_split_clients_module
      • ngx_http_ssi_module
      • ngx_http_ssl_module
      • ngx_http_status_module(过时)
      • ngx_http_stub_status_module
      • ngx_http_sub_module
      • ngx_http_upstream_module
      • ngx_http_upstream_conf_module
      • ngx_http_upstream_hc_module
      • ngx_http_userid_module
      • ngx_http_uwsgi_module
      • ngx_http_v2_module
      • ngx_http_xslt_module
    • Mail
      • ngx_mail_core_module
      • ngx_mail_auth_http_module
      • ngx_mail_proxy_module
      • ngx_mail_ssl_module
      • ngx_mail_imap_module
      • ngx_mail_pop3_module
      • ngx_mail_smtp_module
    • Stream
      • ngx_stream_core_module
      • ngx_stream_access_module
      • ngx_stream_geo_module
      • ngx_stream_geoip_module
      • ngx_stream_js_module
      • ngx_stream_keyval_module
      • ngx_stream_limit_conn_module
      • ngx_stream_log_module
      • ngx_stream_map_module
      • ngx_stream_proxy_module
      • ngx_stream_realip_module
      • ngx_stream_return_module
      • ngx_stream_split_clients_module
      • ngx_stream_ssl_module
      • ngx_stream_ssl_preread_module
      • ngx_stream_upstream_module
      • ngx_stream_upstream_hc_module
      • ngx_stream_zone_sync_module
    • 其他
      • ngx_google_perftools_module
由 GitBook 提供支持
在本页
  • 示例配置
  • 指令
  • image_filter
  • image_filter_buffer
  • image_filter_interlace
  • image_filter_jpeg_quality
  • image_filter_sharpen
  • image_filter_transparency
  • image_filter_webp_quality
  • 原文档
  1. 核心功能
  2. HTTP

ngx_http_image_filter_module

上一页ngx_http_hls_module下一页ngx_http_index_module

最后更新于5年前

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

此模块不是默认构建的,可以使用 --with-http_image_filter_module 配置参数启用。

该模块使用了 库。建议使用该库的最新版本。

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

-

说明

语法

image_filter off; image_filter test; image_filter size; image_filter rotate 90 | 180 | 270; image_filter resize width height; image_filter crop width height;

默认

image_filter off;

上下文

location

设置图片执行的转换类型:

  • off

    关闭对 location 模块的处理

  • test

    确保响应是 JPEG、GIF、PNG 或 WebP 格式的图片。否则,返回 415(不支持的媒体类型)错误。

  • size

    以 JSON 格式输出图片的信息,例如:

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

    发生错误时,输出如下:

      {}
  • rotate 90|180|270

    将图片逆时针旋转指定的度数。参数值可以包含变量。此模式可以单独使用,也可以与调整大小和裁剪转换一起使用。

  • resize width height

    按比例将图片缩小到指定的尺寸。要只指定一个维度,可以将另一个维度指定为 -。当发生错误,服务器将返回 415 状态码(不支持的媒体类型)。参数值可以包含变量。当与 rotate 参数一起使用时,旋转变换将在缩小变换之后执行。

  • crop width height

    按比例将图片缩小到较大的一边,并裁剪另一边多余的边缘。要只指定一个维度,可以将另一个维度指定为 -。当发生错误,服务器将返回 415 状态码(不支持的媒体类型)。参数值可以包含变量。当与 rotate 参数一起使用时,旋转变换将在缩小变换之前执行。

image_filter_buffer

-

说明

语法

image_filter_buffer size;

默认

image_filter_buffer 1M;

上下文

http、server、location

设置用于读取图片的缓冲区的最大大小。当超过指定大小时,服务器返回 415 错误状态码(不支持的媒体类型)。

image_filter_interlace

-

说明

语法

image_filter_interlace on | off;

默认

image_filter_interlace off;

上下文

http、server、location

提示

该指令在 1.3.15 版本中出现

如果启用此选项,图片最后将被逐行扫描。对于 JPEG,图片最终将采用逐行 JPEG 格式。

image_filter_jpeg_quality

-

说明

语法

image_filter_jpeg_quality quality;

默认

image_filter_jpeg_quality 75;

上下文

http、server、location

设置 JPEG 图片的转换质量。可接受的值范围在 1 到 100 之间。较小的值意味着较低的图片质量和较少的数据传输。最大的推荐值是 95,参数值可以包含变量。

image_filter_sharpen

-

说明

语法

image_filter_sharpen percent;

默认

image_filter_sharpen 0;

上下文

http、server、location

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

image_filter_transparency

-

说明

语法

image_filter_transparency on | off;

默认

image_filter_transparency on;

上下文

http、server、location

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

image_filter_webp_quality

-

说明

语法

image_filter_webp_quality quality;

默认

image_filter_webp_quality 80;

上下文

http、server、location

提示

该指令在 1.11.6 版本中出现

设置 WebP 图片的转换质量。可接受的值在 1 到 100 之间。较小的值意味着较低的图片质量和较少的数据传输。参数值可以包含变量。

原文档

http://nginx.org/en/docs/http/ngx_http_image_filter_module.html
libgd
指令
image_filter
image_filter_buffer
image_filter_interlace
image_filter_jpeg_quality
image_filter_sharpen
image_filter_transparency
image_filter_webp_quality