模块 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
配置Directives
示例

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

默认情况下,此模块不是构建的,应使用 configuration 参数启用它。--with-http_image_filter_module

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

WebP 格式支持出现在 1.11.6 版中。 要以这种格式转换图像, 该库必须使用 WebP 支持进行编译。libgd

示例配置

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

location = /empty {
    empty_gif;
}

Directives

语法: 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
关闭周围位置的模块处理。
test
确保响应是 JPEG、GIF、PNG 或 WebP 格式的图像。 否则, 415(不支持的媒体类型) error 返回。
size
以 JSON 格式输出有关图像的信息,例如:
{ "img" : { "width": 100, "height": 100, "type": "gif" } }
如果出现错误,则输出如下:
{}
rotate 90||180270
将图像逆时针旋转指定的度数。 Parameter value 可以包含变量。 此模式可以单独使用,也可以与 和 转换一起使用。resizecrop
resize width height
按比例将图像缩小到指定大小。 要仅减少一个维度,可以将另一个维度指定为 “”. 如果出现错误,服务器将返回代码 415(不支持的媒体类型)。 参数值可以包含变量。 当与参数 旋转发生在 reduction 之后-rotate
crop width height
按比例将图像缩小到较大的边大小 并裁剪另一侧的无关边缘。 要仅减少一个维度,可以将另一个维度指定为 “”. 如果出现错误,服务器将返回代码 415(不支持的媒体类型)。 参数值可以包含变量。 当与参数 旋转发生在 reduction 之前-rotate

语法: image_filter_buffer size;
默认值:
image_filter_buffer 1M;
上下文: http, ,serverlocation

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

语法: image_filter_interlace on | off;
默认值:
image_filter_interlace off;
上下文: http, ,serverlocation

该Directives出现在版本 1.3.15 中。

如果启用,则最终图像将被隔行扫描。 对于 JPEG,最终图像将采用“渐进式 JPEG”格式。

语法: image_filter_jpeg_quality quality;
默认值:
image_filter_jpeg_quality 75;
上下文: http, ,serverlocation

设置转换后的 JPEG 图像的所需值。 可接受的值在 1 到 100 之间。 较小的值通常意味着较低的图像质量和较少的传输数据。 建议的最大值为 95。 Parameter value 可以包含变量。quality

语法: image_filter_sharpen percent;
默认值:
image_filter_sharpen 0;
上下文: http, ,serverlocation

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

语法: image_filter_transparency on|off;
默认值:
image_filter_transparency on;
上下文: http, ,serverlocation

定义变换时是否应保留透明度 具有调色板指定颜色的 GIF 图像或 PNG 图像。 透明度的损失会导致图像质量更好的图像。 PNG 中的 Alpha 通道透明度始终保留。

语法: image_filter_webp_quality quality;
默认值:
image_filter_webp_quality 80;
上下文: http, ,serverlocation

该Directives出现在版本 1.11.6 中。

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