From 8a2124dc6dbed9d32eed037a4e00661848e689f6 Mon Sep 17 00:00:00 2001 From: Maxim Guryanov Date: Wed, 21 Feb 2018 14:27:26 +0500 Subject: [PATCH 1/4] add: resize by any single dimension --- ngx_http_image_filter_module.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/ngx_http_image_filter_module.c b/ngx_http_image_filter_module.c index f6d7439..876eb37 100644 --- a/ngx_http_image_filter_module.c +++ b/ngx_http_image_filter_module.c @@ -621,28 +621,36 @@ ngx_http_image_process(ngx_http_request_t *r) return ngx_http_image_resize(r, ctx); } } - ctx->max_width = ngx_http_image_filter_get_value(r, conf->wcv, conf->width); - if (ctx->max_width == 0) { + ctx->max_width = ngx_http_image_filter_get_value( + r, + conf->wcv, + conf->width + ); + + if (ctx->max_width == 0 && + conf->filter != NGX_HTTP_IMAGE_RESIZE) { return NULL; } - ctx->max_height = ngx_http_image_filter_get_value(r, conf->hcv, - conf->height); - if (ctx->max_height == 0) { + ctx->max_height = ngx_http_image_filter_get_value( + r, + conf->hcv, + conf->height + ); + + if (ctx->max_height == 0 && + conf->filter != NGX_HTTP_IMAGE_RESIZE) { return NULL; } - if (rc == NGX_OK - && ctx->width <= ctx->max_width - && ctx->height <= ctx->max_height - && ctx->angle == 0 - && !ctx->force - && !conf->watermark.data) - { - return ngx_http_image_asis(r, ctx); + if (ctx->max_width == 0 && ctx->max_height == 0) { + return NULL; } + if(ctx->max_width == 0) ctx->max_width =ctx->width; + if(ctx->max_height == 0) ctx->max_height=ctx->height; + return ngx_http_image_resize(r, ctx); } From e76225233a131133a9d61b1590db2d26a5793eb3 Mon Sep 17 00:00:00 2001 From: Maxim Guryanov Date: Wed, 21 Feb 2018 14:59:28 +0500 Subject: [PATCH 2/4] add: crop by any single dimension --- ngx_http_image_filter_module.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/ngx_http_image_filter_module.c b/ngx_http_image_filter_module.c index 876eb37..a2caaac 100644 --- a/ngx_http_image_filter_module.c +++ b/ngx_http_image_filter_module.c @@ -628,22 +628,12 @@ ngx_http_image_process(ngx_http_request_t *r) conf->width ); - if (ctx->max_width == 0 && - conf->filter != NGX_HTTP_IMAGE_RESIZE) { - return NULL; - } - ctx->max_height = ngx_http_image_filter_get_value( r, conf->hcv, conf->height ); - if (ctx->max_height == 0 && - conf->filter != NGX_HTTP_IMAGE_RESIZE) { - return NULL; - } - if (ctx->max_width == 0 && ctx->max_height == 0) { return NULL; } From b841788efdbc0c23dbc87b72c04fbd62bfe5245c Mon Sep 17 00:00:00 2001 From: Maxim Guryanov Date: Wed, 21 Feb 2018 16:01:51 +0500 Subject: [PATCH 3/4] chg: update README specification --- README.md | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0cda677..5ae2da7 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ image_filter watermark; image_filter_watermark_width_from 300; image_filter_watermark_height_from 400; - + image_filter_watermark "PATH_TO_FILE"; image_filter_watermark_position center-center; # top-left|top-right|bottom-right|bottom-left|right-center|left-center|bottom-center|top-center|center-center|center-random` ``` @@ -77,3 +77,43 @@ Usage with resize and crop: image_filter_watermark_position center-center; } ``` + +Resize and crop can omit any dimension value + +* For example, nginx locations configuration: + +``` +location /resize/ { + alias /path/to/backgraund/image; + + image_filter resize $arg_w $arg_h; + + image_filter_watermark /path/to/watermark/image; + image_filter_watermark_position center-center; +} + +location /crop/ { + alias /path/to/backgraund/image; + + image_filter crop $arg_w $arg_h; + + image_filter_watermark /path/to/watermark/image; + image_filter_watermark_position center-center; +} +``` + +* Requests with args: + +1. for proportionally reduces an image to the specified width + +``` + http://localhost/resize/test.png?w=200 + http://localhost/resize/test.png?w=200&h=- +``` + +2. for proportionally reduces an image to the width size and crops by height + +``` + http://localhost/crop/test.png?h=250 + http://localhost/crop/tets.png?w=-&h=250 +``` From eaba42ab8e372244a7486c5365e12f6cc5db2fe0 Mon Sep 17 00:00:00 2001 From: Maxim Guryanov Date: Wed, 21 Feb 2018 16:49:06 +0500 Subject: [PATCH 4/4] fix: README grammar mistakes --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5ae2da7..f5746ab 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ Resize and crop can omit any dimension value ``` location /resize/ { - alias /path/to/backgraund/image; + alias /path/to/background/image; image_filter resize $arg_w $arg_h; @@ -93,7 +93,7 @@ location /resize/ { } location /crop/ { - alias /path/to/backgraund/image; + alias /path/to/background/image; image_filter crop $arg_w $arg_h;