Klaus Demo nginx / 5bb71a4
Merge of r4266, r4308, r4309: Image filter changes: *) The "image_filter_sharpen" directive. *) Cosmetics. *) Fixed "rotate" to always work when combined with "resize/crop". Maxim Dounin 10 years ago
1 changed file(s) with 78 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
4040 ngx_uint_t height;
4141 ngx_uint_t angle;
4242 ngx_uint_t jpeg_quality;
43 ngx_uint_t sharpen;
4344
4445 ngx_flag_t transparency;
4546
4748 ngx_http_complex_value_t *hcv;
4849 ngx_http_complex_value_t *acv;
4950 ngx_http_complex_value_t *jqcv;
51 ngx_http_complex_value_t *shcv;
5052
5153 size_t buffer_size;
5254 } ngx_http_image_filter_conf_t;
104106 void *conf);
105107 static char *ngx_http_image_filter_jpeg_quality(ngx_conf_t *cf,
106108 ngx_command_t *cmd, void *conf);
109 static char *ngx_http_image_filter_sharpen(ngx_conf_t *cf, ngx_command_t *cmd,
110 void *conf);
107111 static ngx_int_t ngx_http_image_filter_init(ngx_conf_t *cf);
108112
109113
110114 static ngx_command_t ngx_http_image_filter_commands[] = {
111115
112116 { ngx_string("image_filter"),
113 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE13|NGX_CONF_TAKE2,
117 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE123,
114118 ngx_http_image_filter,
115119 NGX_HTTP_LOC_CONF_OFFSET,
116120 0,
119123 { ngx_string("image_filter_jpeg_quality"),
120124 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
121125 ngx_http_image_filter_jpeg_quality,
126 NGX_HTTP_LOC_CONF_OFFSET,
127 0,
128 NULL },
129
130 { ngx_string("image_filter_sharpen"),
131 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
132 ngx_http_image_filter_sharpen,
122133 NGX_HTTP_LOC_CONF_OFFSET,
123134 0,
124135 NULL },
723734 ngx_http_image_resize(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx)
724735 {
725736 int sx, sy, dx, dy, ox, oy, ax, ay, size,
726 colors, palette, transparent,
737 colors, palette, transparent, sharpen,
727738 red, green, blue, t;
728739 u_char *out;
729740 ngx_buf_t *b;
947958 gdImageColorTransparent(dst, gdImageColorExact(dst, red, green, blue));
948959 }
949960
961 sharpen = ngx_http_image_filter_get_value(r, conf->shcv, conf->sharpen);
962 if (sharpen > 0) {
963 gdImageSharpen(dst, sharpen);
964 }
965
950966 out = ngx_http_image_out(r, ctx->type, dst, &size);
951967
952968 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
11551171
11561172 conf->filter = NGX_CONF_UNSET_UINT;
11571173 conf->jpeg_quality = NGX_CONF_UNSET_UINT;
1174 conf->sharpen = NGX_CONF_UNSET_UINT;
11581175 conf->angle = NGX_CONF_UNSET_UINT;
11591176 conf->transparency = NGX_CONF_UNSET;
11601177 conf->buffer_size = NGX_CONF_UNSET_SIZE;
11901207 conf->jqcv = prev->jqcv;
11911208 }
11921209
1210 ngx_conf_merge_uint_value(conf->sharpen, prev->sharpen, 0);
1211
1212 if (conf->shcv == NULL) {
1213 conf->shcv = prev->shcv;
1214 }
1215
11931216 ngx_conf_merge_uint_value(conf->angle, prev->angle, 0);
11941217 if (conf->acv == NULL) {
11951218 conf->acv = prev->acv;
12381261 } else if (cf->args->nelts == 3) {
12391262
12401263 if (ngx_strcmp(value[i].data, "rotate") == 0) {
1241 imcf->filter = NGX_HTTP_IMAGE_ROTATE;
1264 if (imcf->filter != NGX_HTTP_IMAGE_RESIZE
1265 && imcf->filter != NGX_HTTP_IMAGE_CROP)
1266 {
1267 imcf->filter = NGX_HTTP_IMAGE_ROTATE;
1268 }
12421269
12431270 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
12441271
13811408
13821409 if (n <= 0) {
13831410 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1384 "invalid parameter \"%V\"", &value[1]);
1411 "invalid value \"%V\"", &value[1]);
13851412 return NGX_CONF_ERROR;
13861413 }
13871414
14001427 }
14011428
14021429
1430 static char *
1431 ngx_http_image_filter_sharpen(ngx_conf_t *cf, ngx_command_t *cmd,
1432 void *conf)
1433 {
1434 ngx_http_image_filter_conf_t *imcf = conf;
1435
1436 ngx_str_t *value;
1437 ngx_int_t n;
1438 ngx_http_complex_value_t cv;
1439 ngx_http_compile_complex_value_t ccv;
1440
1441 value = cf->args->elts;
1442
1443 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
1444
1445 ccv.cf = cf;
1446 ccv.value = &value[1];
1447 ccv.complex_value = &cv;
1448
1449 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
1450 return NGX_CONF_ERROR;
1451 }
1452
1453 if (cv.lengths == NULL) {
1454 n = ngx_http_image_filter_value(&value[1]);
1455
1456 if (n < 0) {
1457 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1458 "invalid value \"%V\"", &value[1]);
1459 return NGX_CONF_ERROR;
1460 }
1461
1462 imcf->sharpen = (ngx_uint_t) n;
1463
1464 } else {
1465 imcf->shcv = ngx_palloc(cf->pool, sizeof(ngx_http_complex_value_t));
1466 if (imcf->shcv == NULL) {
1467 return NGX_CONF_ERROR;
1468 }
1469
1470 *imcf->shcv = cv;
1471 }
1472
1473 return NGX_CONF_OK;
1474 }
1475
1476
14031477 static ngx_int_t
14041478 ngx_http_image_filter_init(ngx_conf_t *cf)
14051479 {