comparison src/http/modules/ngx_http_image_filter_module.c @ 648:f200748c0ac8 NGINX_1_1_8

nginx 1.1.8 *) Change: the ngx_http_limit_zone_module was renamed to the ngx_http_limit_conn_module. *) Change: the "limit_zone" directive was superseded by the "limit_conn_zone" directive with a new syntax. *) Feature: support for multiple "limit_conn" limits on the same level. *) Feature: the "image_filter_sharpen" directive. *) Bugfix: a segmentation fault might occur in a worker process if resolver got a big DNS response. Thanks to Ben Hawkes. *) Bugfix: in cache key calculation if internal MD5 implementation was used; the bug had appeared in 1.0.4. *) Bugfix: the "If-Modified-Since", "If-Range", etc. client request header lines might be passed to backend while caching; or not passed without caching if caching was enabled in another part of the configuration. *) Bugfix: the module ngx_http_mp4_module sent incorrect "Content-Length" response header line if the "start" argument was used. Thanks to Piotr Sikora.
author Igor Sysoev <http://sysoev.ru>
date Mon, 14 Nov 2011 00:00:00 +0400
parents d4da38525468
children 4d05413aebad
comparison
equal deleted inserted replaced
647:bec017127243 648:f200748c0ac8
39 ngx_uint_t filter; 39 ngx_uint_t filter;
40 ngx_uint_t width; 40 ngx_uint_t width;
41 ngx_uint_t height; 41 ngx_uint_t height;
42 ngx_uint_t angle; 42 ngx_uint_t angle;
43 ngx_uint_t jpeg_quality; 43 ngx_uint_t jpeg_quality;
44 ngx_uint_t sharpen;
44 45
45 ngx_flag_t transparency; 46 ngx_flag_t transparency;
46 47
47 ngx_http_complex_value_t *wcv; 48 ngx_http_complex_value_t *wcv;
48 ngx_http_complex_value_t *hcv; 49 ngx_http_complex_value_t *hcv;
49 ngx_http_complex_value_t *acv; 50 ngx_http_complex_value_t *acv;
50 ngx_http_complex_value_t *jqcv; 51 ngx_http_complex_value_t *jqcv;
52 ngx_http_complex_value_t *shcv;
51 53
52 size_t buffer_size; 54 size_t buffer_size;
53 } ngx_http_image_filter_conf_t; 55 } ngx_http_image_filter_conf_t;
54 56
55 57
103 void *child); 105 void *child);
104 static char *ngx_http_image_filter(ngx_conf_t *cf, ngx_command_t *cmd, 106 static char *ngx_http_image_filter(ngx_conf_t *cf, ngx_command_t *cmd,
105 void *conf); 107 void *conf);
106 static char *ngx_http_image_filter_jpeg_quality(ngx_conf_t *cf, 108 static char *ngx_http_image_filter_jpeg_quality(ngx_conf_t *cf,
107 ngx_command_t *cmd, void *conf); 109 ngx_command_t *cmd, void *conf);
110 static char *ngx_http_image_filter_sharpen(ngx_conf_t *cf, ngx_command_t *cmd,
111 void *conf);
108 static ngx_int_t ngx_http_image_filter_init(ngx_conf_t *cf); 112 static ngx_int_t ngx_http_image_filter_init(ngx_conf_t *cf);
109 113
110 114
111 static ngx_command_t ngx_http_image_filter_commands[] = { 115 static ngx_command_t ngx_http_image_filter_commands[] = {
112 116
118 NULL }, 122 NULL },
119 123
120 { ngx_string("image_filter_jpeg_quality"), 124 { ngx_string("image_filter_jpeg_quality"),
121 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, 125 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
122 ngx_http_image_filter_jpeg_quality, 126 ngx_http_image_filter_jpeg_quality,
127 NGX_HTTP_LOC_CONF_OFFSET,
128 0,
129 NULL },
130
131 { ngx_string("image_filter_sharpen"),
132 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
133 ngx_http_image_filter_sharpen,
123 NGX_HTTP_LOC_CONF_OFFSET, 134 NGX_HTTP_LOC_CONF_OFFSET,
124 0, 135 0,
125 NULL }, 136 NULL },
126 137
127 { ngx_string("image_filter_transparency"), 138 { ngx_string("image_filter_transparency"),
722 733
723 static ngx_buf_t * 734 static ngx_buf_t *
724 ngx_http_image_resize(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx) 735 ngx_http_image_resize(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx)
725 { 736 {
726 int sx, sy, dx, dy, ox, oy, ax, ay, size, 737 int sx, sy, dx, dy, ox, oy, ax, ay, size,
727 colors, palette, transparent, 738 colors, palette, transparent, sharpen,
728 red, green, blue, t; 739 red, green, blue, t;
729 u_char *out; 740 u_char *out;
730 ngx_buf_t *b; 741 ngx_buf_t *b;
731 ngx_uint_t resize; 742 ngx_uint_t resize;
732 gdImagePtr src, dst; 743 gdImagePtr src, dst;
946 957
947 if (transparent != -1 && colors) { 958 if (transparent != -1 && colors) {
948 gdImageColorTransparent(dst, gdImageColorExact(dst, red, green, blue)); 959 gdImageColorTransparent(dst, gdImageColorExact(dst, red, green, blue));
949 } 960 }
950 961
962 sharpen = ngx_http_image_filter_get_value(r, conf->shcv, conf->sharpen);
963 if (sharpen > 0) {
964 gdImageSharpen(dst, sharpen);
965 }
966
951 out = ngx_http_image_out(r, ctx->type, dst, &size); 967 out = ngx_http_image_out(r, ctx->type, dst, &size);
952 968
953 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 969 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
954 "image: %d x %d %d", sx, sy, colors); 970 "image: %d x %d %d", sx, sy, colors);
955 971
1154 return NULL; 1170 return NULL;
1155 } 1171 }
1156 1172
1157 conf->filter = NGX_CONF_UNSET_UINT; 1173 conf->filter = NGX_CONF_UNSET_UINT;
1158 conf->jpeg_quality = NGX_CONF_UNSET_UINT; 1174 conf->jpeg_quality = NGX_CONF_UNSET_UINT;
1175 conf->sharpen = NGX_CONF_UNSET_UINT;
1159 conf->angle = NGX_CONF_UNSET_UINT; 1176 conf->angle = NGX_CONF_UNSET_UINT;
1160 conf->transparency = NGX_CONF_UNSET; 1177 conf->transparency = NGX_CONF_UNSET;
1161 conf->buffer_size = NGX_CONF_UNSET_SIZE; 1178 conf->buffer_size = NGX_CONF_UNSET_SIZE;
1162 1179
1163 return conf; 1180 return conf;
1189 1206
1190 if (conf->jqcv == NULL) { 1207 if (conf->jqcv == NULL) {
1191 conf->jqcv = prev->jqcv; 1208 conf->jqcv = prev->jqcv;
1192 } 1209 }
1193 1210
1211 ngx_conf_merge_uint_value(conf->sharpen, prev->sharpen, 0);
1212
1213 if (conf->shcv == NULL) {
1214 conf->shcv = prev->shcv;
1215 }
1216
1194 ngx_conf_merge_uint_value(conf->angle, prev->angle, 0); 1217 ngx_conf_merge_uint_value(conf->angle, prev->angle, 0);
1195 if (conf->acv == NULL) { 1218 if (conf->acv == NULL) {
1196 conf->acv = prev->acv; 1219 conf->acv = prev->acv;
1197 } 1220 }
1198 1221
1399 1422
1400 return NGX_CONF_OK; 1423 return NGX_CONF_OK;
1401 } 1424 }
1402 1425
1403 1426
1427 static char *
1428 ngx_http_image_filter_sharpen(ngx_conf_t *cf, ngx_command_t *cmd,
1429 void *conf)
1430 {
1431 ngx_http_image_filter_conf_t *imcf = conf;
1432
1433 ngx_str_t *value;
1434 ngx_int_t n;
1435 ngx_http_complex_value_t cv;
1436 ngx_http_compile_complex_value_t ccv;
1437
1438 value = cf->args->elts;
1439
1440 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
1441
1442 ccv.cf = cf;
1443 ccv.value = &value[1];
1444 ccv.complex_value = &cv;
1445
1446 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
1447 return NGX_CONF_ERROR;
1448 }
1449
1450 if (cv.lengths == NULL) {
1451 n = ngx_http_image_filter_value(&value[1]);
1452
1453 if (n < 0) {
1454 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1455 "invalid parameter \"%V\"", &value[1]);
1456 return NGX_CONF_ERROR;
1457 }
1458
1459 imcf->sharpen = (ngx_uint_t) n;
1460
1461 } else {
1462 imcf->shcv = ngx_palloc(cf->pool, sizeof(ngx_http_complex_value_t));
1463 if (imcf->shcv == NULL) {
1464 return NGX_CONF_ERROR;
1465 }
1466
1467 *imcf->shcv = cv;
1468 }
1469
1470 return NGX_CONF_OK;
1471 }
1472
1473
1404 static ngx_int_t 1474 static ngx_int_t
1405 ngx_http_image_filter_init(ngx_conf_t *cf) 1475 ngx_http_image_filter_init(ngx_conf_t *cf)
1406 { 1476 {
1407 ngx_http_next_header_filter = ngx_http_top_header_filter; 1477 ngx_http_next_header_filter = ngx_http_top_header_filter;
1408 ngx_http_top_header_filter = ngx_http_image_header_filter; 1478 ngx_http_top_header_filter = ngx_http_image_header_filter;