comparison src/http/modules/ngx_http_image_filter_module.c @ 642:1b80544421e8 NGINX_1_0_11

nginx 1.0.11 *) Change: now double quotes are encoded in an "echo" SSI-command output. Thanks to Zaur Abasmirzoev. *) Feature: the "image_filter_sharpen" directive. *) Bugfix: a segmentation fault might occur in a worker process if SNI was used; the bug had appeared in 1.0.9. *) Bugfix: SIGWINCH signal did not work after first binary upgrade; the bug had appeared in 1.0.9. *) 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: in the "scgi_param" directive, if complex parameters were used. *) Bugfix: "add_header" and "expires" directives did not work if a request was proxied and response status code was 206. *) Bugfix: in the "expires @time" directive. *) Bugfix: in the ngx_http_flv_module. Thanks to Piotr Sikora. *) Bugfix: in the ngx_http_mp4_module. *) Bugfix: nginx could not be built on FreeBSD 10. *) Bugfix: nginx could not be built on AIX.
author Igor Sysoev <http://sysoev.ru>
date Thu, 15 Dec 2011 00:00:00 +0400
parents d4da38525468
children ad25218fd14b
comparison
equal deleted inserted replaced
641:e21c9e01ce08 642:1b80544421e8
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
113 { ngx_string("image_filter"), 117 { ngx_string("image_filter"),
114 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE13|NGX_CONF_TAKE2, 118 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE123,
115 ngx_http_image_filter, 119 ngx_http_image_filter,
116 NGX_HTTP_LOC_CONF_OFFSET, 120 NGX_HTTP_LOC_CONF_OFFSET,
117 0, 121 0,
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
1237 return NGX_CONF_OK; 1260 return NGX_CONF_OK;
1238 1261
1239 } else if (cf->args->nelts == 3) { 1262 } else if (cf->args->nelts == 3) {
1240 1263
1241 if (ngx_strcmp(value[i].data, "rotate") == 0) { 1264 if (ngx_strcmp(value[i].data, "rotate") == 0) {
1242 imcf->filter = NGX_HTTP_IMAGE_ROTATE; 1265 if (imcf->filter != NGX_HTTP_IMAGE_RESIZE
1266 && imcf->filter != NGX_HTTP_IMAGE_CROP)
1267 {
1268 imcf->filter = NGX_HTTP_IMAGE_ROTATE;
1269 }
1243 1270
1244 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); 1271 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
1245 1272
1246 ccv.cf = cf; 1273 ccv.cf = cf;
1247 ccv.value = &value[++i]; 1274 ccv.value = &value[++i];
1380 if (cv.lengths == NULL) { 1407 if (cv.lengths == NULL) {
1381 n = ngx_http_image_filter_value(&value[1]); 1408 n = ngx_http_image_filter_value(&value[1]);
1382 1409
1383 if (n <= 0) { 1410 if (n <= 0) {
1384 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 1411 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1385 "invalid parameter \"%V\"", &value[1]); 1412 "invalid value \"%V\"", &value[1]);
1386 return NGX_CONF_ERROR; 1413 return NGX_CONF_ERROR;
1387 } 1414 }
1388 1415
1389 imcf->jpeg_quality = (ngx_uint_t) n; 1416 imcf->jpeg_quality = (ngx_uint_t) n;
1390 1417
1399 1426
1400 return NGX_CONF_OK; 1427 return NGX_CONF_OK;
1401 } 1428 }
1402 1429
1403 1430
1431 static char *
1432 ngx_http_image_filter_sharpen(ngx_conf_t *cf, ngx_command_t *cmd,
1433 void *conf)
1434 {
1435 ngx_http_image_filter_conf_t *imcf = conf;
1436
1437 ngx_str_t *value;
1438 ngx_int_t n;
1439 ngx_http_complex_value_t cv;
1440 ngx_http_compile_complex_value_t ccv;
1441
1442 value = cf->args->elts;
1443
1444 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
1445
1446 ccv.cf = cf;
1447 ccv.value = &value[1];
1448 ccv.complex_value = &cv;
1449
1450 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
1451 return NGX_CONF_ERROR;
1452 }
1453
1454 if (cv.lengths == NULL) {
1455 n = ngx_http_image_filter_value(&value[1]);
1456
1457 if (n < 0) {
1458 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1459 "invalid value \"%V\"", &value[1]);
1460 return NGX_CONF_ERROR;
1461 }
1462
1463 imcf->sharpen = (ngx_uint_t) n;
1464
1465 } else {
1466 imcf->shcv = ngx_palloc(cf->pool, sizeof(ngx_http_complex_value_t));
1467 if (imcf->shcv == NULL) {
1468 return NGX_CONF_ERROR;
1469 }
1470
1471 *imcf->shcv = cv;
1472 }
1473
1474 return NGX_CONF_OK;
1475 }
1476
1477
1404 static ngx_int_t 1478 static ngx_int_t
1405 ngx_http_image_filter_init(ngx_conf_t *cf) 1479 ngx_http_image_filter_init(ngx_conf_t *cf)
1406 { 1480 {
1407 ngx_http_next_header_filter = ngx_http_top_header_filter; 1481 ngx_http_next_header_filter = ngx_http_top_header_filter;
1408 ngx_http_top_header_filter = ngx_http_image_header_filter; 1482 ngx_http_top_header_filter = ngx_http_image_header_filter;