mirror of
https://github.com/nginx/nginx.git
synced 2025-02-25 18:55:26 -06:00
image_filter_transparency
This commit is contained in:
@@ -40,6 +40,8 @@ typedef struct {
|
|||||||
ngx_uint_t height;
|
ngx_uint_t height;
|
||||||
ngx_int_t jpeg_quality;
|
ngx_int_t jpeg_quality;
|
||||||
|
|
||||||
|
ngx_flag_t transparency;
|
||||||
|
|
||||||
ngx_http_complex_value_t *wcv;
|
ngx_http_complex_value_t *wcv;
|
||||||
ngx_http_complex_value_t *hcv;
|
ngx_http_complex_value_t *hcv;
|
||||||
|
|
||||||
@@ -115,6 +117,13 @@ static ngx_command_t ngx_http_image_filter_commands[] = {
|
|||||||
offsetof(ngx_http_image_filter_conf_t, jpeg_quality),
|
offsetof(ngx_http_image_filter_conf_t, jpeg_quality),
|
||||||
NULL },
|
NULL },
|
||||||
|
|
||||||
|
{ ngx_string("image_filter_transparency"),
|
||||||
|
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
||||||
|
ngx_conf_set_flag_slot,
|
||||||
|
NGX_HTTP_LOC_CONF_OFFSET,
|
||||||
|
offsetof(ngx_http_image_filter_conf_t, transparency),
|
||||||
|
NULL },
|
||||||
|
|
||||||
{ ngx_string("image_filter_buffer"),
|
{ ngx_string("image_filter_buffer"),
|
||||||
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
||||||
ngx_conf_set_size_slot,
|
ngx_conf_set_size_slot,
|
||||||
@@ -678,8 +687,9 @@ ngx_http_image_size(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx)
|
|||||||
static ngx_buf_t *
|
static ngx_buf_t *
|
||||||
ngx_http_image_resize(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx)
|
ngx_http_image_resize(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx)
|
||||||
{
|
{
|
||||||
int sx, sy, dx, dy, ox, oy,
|
int sx, sy, dx, dy, ox, oy, size,
|
||||||
colors, transparent, red, green, blue, size;
|
colors, palette, transparent,
|
||||||
|
red, green, blue;
|
||||||
u_char *out;
|
u_char *out;
|
||||||
ngx_buf_t *b;
|
ngx_buf_t *b;
|
||||||
ngx_uint_t resize;
|
ngx_uint_t resize;
|
||||||
@@ -706,17 +716,29 @@ ngx_http_image_resize(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
colors = gdImageColorsTotal(src);
|
colors = gdImageColorsTotal(src);
|
||||||
|
|
||||||
|
if (colors && conf->transparency) {
|
||||||
transparent = gdImageGetTransparent(src);
|
transparent = gdImageGetTransparent(src);
|
||||||
|
|
||||||
if (transparent != -1 && colors) {
|
if (transparent != -1) {
|
||||||
|
palette = colors;
|
||||||
red = gdImageRed(src, transparent);
|
red = gdImageRed(src, transparent);
|
||||||
green = gdImageGreen(src, transparent);
|
green = gdImageGreen(src, transparent);
|
||||||
blue = gdImageBlue(src, transparent);
|
blue = gdImageBlue(src, transparent);
|
||||||
gdImageColorTransparent(src, -1);
|
|
||||||
|
|
||||||
} else {
|
goto transparent;
|
||||||
red = 0; green = 0; blue = 0;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
palette = 0;
|
||||||
|
transparent = -1;
|
||||||
|
red = 0;
|
||||||
|
green = 0;
|
||||||
|
blue = 0;
|
||||||
|
|
||||||
|
transparent:
|
||||||
|
|
||||||
|
gdImageColorTransparent(src, -1);
|
||||||
|
|
||||||
dx = sx;
|
dx = sx;
|
||||||
dy = sy;
|
dy = sy;
|
||||||
@@ -762,7 +784,7 @@ ngx_http_image_resize(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (resize) {
|
if (resize) {
|
||||||
dst = ngx_http_image_new(r, dx, dy, colors);
|
dst = ngx_http_image_new(r, dx, dy, palette);
|
||||||
if (dst == NULL) {
|
if (dst == NULL) {
|
||||||
gdImageDestroy(src);
|
gdImageDestroy(src);
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -775,6 +797,10 @@ ngx_http_image_resize(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx)
|
|||||||
|
|
||||||
gdImageCopyResampled(dst, src, 0, 0, 0, 0, dx, dy, sx, sy);
|
gdImageCopyResampled(dst, src, 0, 0, 0, 0, dx, dy, sx, sy);
|
||||||
|
|
||||||
|
if (colors) {
|
||||||
|
gdImageTrueColorToPalette(dst, 1, 256);
|
||||||
|
}
|
||||||
|
|
||||||
gdImageDestroy(src);
|
gdImageDestroy(src);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -822,6 +848,10 @@ ngx_http_image_resize(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx)
|
|||||||
|
|
||||||
gdImageCopy(dst, src, 0, 0, ox, oy, dx - ox, dy - oy);
|
gdImageCopy(dst, src, 0, 0, ox, oy, dx - ox, dy - oy);
|
||||||
|
|
||||||
|
if (colors) {
|
||||||
|
gdImageTrueColorToPalette(dst, 1, 256);
|
||||||
|
}
|
||||||
|
|
||||||
gdImageDestroy(src);
|
gdImageDestroy(src);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1031,6 +1061,7 @@ ngx_http_image_filter_create_conf(ngx_conf_t *cf)
|
|||||||
|
|
||||||
conf->filter = NGX_CONF_UNSET_UINT;
|
conf->filter = NGX_CONF_UNSET_UINT;
|
||||||
conf->jpeg_quality = NGX_CONF_UNSET;
|
conf->jpeg_quality = NGX_CONF_UNSET;
|
||||||
|
conf->transparency = NGX_CONF_UNSET;
|
||||||
conf->buffer_size = NGX_CONF_UNSET_SIZE;
|
conf->buffer_size = NGX_CONF_UNSET_SIZE;
|
||||||
|
|
||||||
return conf;
|
return conf;
|
||||||
@@ -1060,6 +1091,8 @@ ngx_http_image_filter_merge_conf(ngx_conf_t *cf, void *parent, void *child)
|
|||||||
/* 75 is libjpeg default quality */
|
/* 75 is libjpeg default quality */
|
||||||
ngx_conf_merge_value(conf->jpeg_quality, prev->jpeg_quality, 75);
|
ngx_conf_merge_value(conf->jpeg_quality, prev->jpeg_quality, 75);
|
||||||
|
|
||||||
|
ngx_conf_merge_value(conf->transparency, prev->transparency, 1);
|
||||||
|
|
||||||
ngx_conf_merge_size_value(conf->buffer_size, prev->buffer_size,
|
ngx_conf_merge_size_value(conf->buffer_size, prev->buffer_size,
|
||||||
1 * 1024 * 1024);
|
1 * 1024 * 1024);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user