|
20 | 20 | #define NGX_HTTP_IMAGE_ROTATE 5 |
21 | 21 | #define NGX_HTTP_IMAGE_CROP_KEEPX 6 |
22 | 22 | #define NGX_HTTP_IMAGE_CROP_KEEPY 7 |
23 | | -#define NGX_HTTP_IMAGE_SCALE 8 // experimental image resize |
24 | 23 |
|
25 | 24 |
|
26 | 25 | #define NGX_HTTP_IMAGE_START 0 |
@@ -57,7 +56,7 @@ typedef struct { |
57 | 56 | ngx_uint_t sharpen; |
58 | 57 | ngx_uint_t offset_x; |
59 | 58 | ngx_uint_t offset_y; |
60 | | - ngx_uint_t ratio_max; |
| 59 | + ngx_uint_t scale_max; |
61 | 60 |
|
62 | 61 | ngx_flag_t transparency; |
63 | 62 | ngx_flag_t interlace; |
@@ -91,7 +90,7 @@ typedef struct { |
91 | 90 | ngx_uint_t offset_x; |
92 | 91 | ngx_uint_t offset_y; |
93 | 92 | ngx_uint_t angle; |
94 | | - ngx_uint_t ratio_max; |
| 93 | + ngx_uint_t scale_max; |
95 | 94 |
|
96 | 95 | ngx_uint_t phase; |
97 | 96 | ngx_uint_t type; |
@@ -210,11 +209,11 @@ static ngx_command_t ngx_http_image_filter_commands[] = { |
210 | 209 | 0, |
211 | 210 | NULL }, |
212 | 211 |
|
213 | | - { ngx_string("image_filter_ratio_max"), |
| 212 | + { ngx_string("image_filter_scale_max"), |
214 | 213 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
215 | 214 | ngx_conf_set_num_slot, |
216 | 215 | NGX_HTTP_LOC_CONF_OFFSET, |
217 | | - offsetof(ngx_http_image_filter_conf_t, ratio_max), |
| 216 | + offsetof(ngx_http_image_filter_conf_t, scale_max), |
218 | 217 | NULL }, |
219 | 218 |
|
220 | 219 | { ngx_string("image_filter_water_image"), |
@@ -664,8 +663,8 @@ ngx_http_image_process(ngx_http_request_t *r) |
664 | 663 | return NULL; |
665 | 664 | } |
666 | 665 |
|
667 | | - // it's ok since we simply center image |
668 | | - if (conf->filter == NGX_HTTP_IMAGE_SCALE) { |
| 666 | + // scale would force to resize image |
| 667 | + if (conf->scale_max > 1) { |
669 | 668 | ctx->force = 1; |
670 | 669 | } |
671 | 670 |
|
@@ -940,7 +939,7 @@ ngx_http_image_resize(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx) |
940 | 939 | red, green, blue, t, |
941 | 940 | offset_x, offset_y; |
942 | 941 | u_char *out; |
943 | | - double ratio_max, ratio, ratio_h; |
| 942 | + double scale_max, ratio, ratio_h; |
944 | 943 | ngx_buf_t *b; |
945 | 944 | ngx_uint_t resize; |
946 | 945 | gdImagePtr src, dst; |
@@ -993,18 +992,16 @@ ngx_http_image_resize(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx) |
993 | 992 | // ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "FUNC resize started \n"); |
994 | 993 |
|
995 | 994 | // pre-resize if using scale |
996 | | - if (conf->filter == NGX_HTTP_IMAGE_SCALE) { |
997 | | - conf->filter = NGX_HTTP_IMAGE_RESIZE; |
998 | | - // don't allow bigger than double the size? |
999 | | - ratio_max = (double) conf->ratio_max; |
| 995 | + if (conf->scale_max > 1) { |
| 996 | + scale_max = (double) conf->scale_max; |
1000 | 997 | ratio = ((double) ctx->max_width / (double) sx); |
1001 | 998 | ratio_h = ((double) ctx->max_height / (double) sy); |
1002 | 999 | if (ratio_h > ratio) { |
1003 | 1000 | ratio = ratio_h; |
1004 | 1001 | } |
1005 | 1002 |
|
1006 | | - if (ratio > ratio_max) { |
1007 | | - ratio = ratio_max; |
| 1003 | + if (ratio > scale_max) { |
| 1004 | + ratio = scale_max; |
1008 | 1005 | } |
1009 | 1006 |
|
1010 | 1007 | //ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "scale ratio = %d, %d \n", |
@@ -1587,7 +1584,7 @@ ngx_http_image_filter_create_conf(ngx_conf_t *cf) |
1587 | 1584 | conf->buffer_size = NGX_CONF_UNSET_SIZE; |
1588 | 1585 | conf->offset_x = NGX_CONF_UNSET_UINT; |
1589 | 1586 | conf->offset_y = NGX_CONF_UNSET_UINT; |
1590 | | - conf->ratio_max = NGX_CONF_UNSET_UINT; |
| 1587 | + conf->scale_max = NGX_CONF_UNSET_UINT; |
1591 | 1588 |
|
1592 | 1589 | return conf; |
1593 | 1590 | } |
@@ -1672,9 +1669,9 @@ ngx_http_image_filter_merge_conf(ngx_conf_t *cf, void *parent, void *child) |
1672 | 1669 | } |
1673 | 1670 | } |
1674 | 1671 |
|
1675 | | - if (conf->ratio_max == NGX_CONF_UNSET_UINT) { |
| 1672 | + if (conf->scale_max == NGX_CONF_UNSET_UINT) { |
1676 | 1673 | /* 2 is the default max ratio */ |
1677 | | - ngx_conf_merge_uint_value(conf->ratio_max, prev->ratio_max, 2); |
| 1674 | + ngx_conf_merge_uint_value(conf->scale_max, prev->scale_max, 1); |
1678 | 1675 | } |
1679 | 1676 |
|
1680 | 1677 | if (conf->output == NULL) { |
@@ -1720,8 +1717,7 @@ ngx_http_image_filter(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
1720 | 1717 |
|
1721 | 1718 | if (ngx_strcmp(value[i].data, "rotate") == 0) { |
1722 | 1719 | if (imcf->filter != NGX_HTTP_IMAGE_RESIZE |
1723 | | - && imcf->filter != NGX_HTTP_IMAGE_CROP |
1724 | | - && imcf->filter != NGX_HTTP_IMAGE_SCALE) |
| 1720 | + && imcf->filter != NGX_HTTP_IMAGE_CROP) |
1725 | 1721 | { |
1726 | 1722 | imcf->filter = NGX_HTTP_IMAGE_ROTATE; |
1727 | 1723 | } |
@@ -1768,9 +1764,6 @@ ngx_http_image_filter(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
1768 | 1764 | } else if (ngx_strcmp(value[i].data, "crop") == 0) { |
1769 | 1765 | imcf->filter = NGX_HTTP_IMAGE_CROP; |
1770 | 1766 |
|
1771 | | - } else if (ngx_strcmp(value[i].data, "scale") == 0) { |
1772 | | - imcf->filter = NGX_HTTP_IMAGE_SCALE; |
1773 | | - |
1774 | 1767 | } else { |
1775 | 1768 | goto failed; |
1776 | 1769 | } |
|
0 commit comments