Ticket #2454: image_filter_scale.patch
| File image_filter_scale.patch, 3.5 KB (added by , 3 years ago) |
|---|
-
src/http/modules/ngx_http_image_filter_module.c
old new typedef struct { 48 48 49 49 ngx_flag_t transparency; 50 50 ngx_flag_t interlace; 51 ngx_flag_t use_scale_function; 51 52 52 53 ngx_http_complex_value_t *wcv; 53 54 ngx_http_complex_value_t *hcv; … … static ngx_command_t ngx_http_image_fil 163 164 offsetof(ngx_http_image_filter_conf_t, interlace), 164 165 NULL }, 165 166 167 { ngx_string("image_filter_use_scale_function"), 168 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, 169 ngx_conf_set_flag_slot, 170 NGX_HTTP_LOC_CONF_OFFSET, 171 offsetof(ngx_http_image_filter_conf_t, use_scale_function), 172 NULL }, 173 166 174 { ngx_string("image_filter_buffer"), 167 175 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, 168 176 ngx_conf_set_size_slot, … … ngx_http_image_resize(ngx_http_request_t 851 859 852 860 colors = gdImageColorsTotal(src); 853 861 854 if (colors && conf->transparency) {862 if (colors && !conf->use_scale_function && conf->transparency) { 855 863 transparent = gdImageGetTransparent(src); 856 864 857 865 if (transparent != -1) { … … ngx_http_image_resize(ngx_http_request_t 872 880 873 881 transparent: 874 882 875 gdImageColorTransparent(src, -1); 883 if (!conf->use_scale_function) { 884 gdImageColorTransparent(src, -1); 885 } 876 886 877 887 dx = sx; 878 888 dy = sy; … … transparent: 919 929 } 920 930 } 921 931 922 if (resize) { 932 if (resize && conf->use_scale_function) { 933 gdImageSetInterpolationMethod(src, GD_BICUBIC); 934 dst = gdImageScale(src, dx, dy); 935 if (dst == NULL) { 936 gdImageDestroy(src); 937 return NULL; 938 } 939 gdImageDestroy(src); 940 } else if (resize) { 923 941 dst = ngx_http_image_new(r, dx, dy, palette); 924 942 if (dst == NULL) { 925 943 gdImageDestroy(src); … … transparent: 1023 1041 "image crop: %d x %d @ %d x %d", 1024 1042 dx, dy, ox, oy); 1025 1043 1026 if ( colors == 0) {1044 if (!conf->use_scale_function && colors == 0) { 1027 1045 gdImageSaveAlpha(dst, 1); 1028 1046 gdImageAlphaBlending(dst, 0); 1029 1047 } 1030 1048 1031 1049 gdImageCopy(dst, src, 0, 0, ox, oy, dx - ox, dy - oy); 1032 1050 1033 if ( colors) {1051 if (!conf->use_scale_function && colors) { 1034 1052 gdImageTrueColorToPalette(dst, 1, 256); 1035 1053 } 1036 1054 … … transparent: 1038 1056 } 1039 1057 } 1040 1058 1041 if ( transparent != -1 && colors) {1059 if (!conf->use_scale_function && transparent != -1 && colors) { 1042 1060 gdImageColorTransparent(dst, gdImageColorExact(dst, red, green, blue)); 1043 1061 } 1044 1062 … … ngx_http_image_filter_create_conf(ngx_co 1301 1319 conf->sharpen = NGX_CONF_UNSET_UINT; 1302 1320 conf->transparency = NGX_CONF_UNSET; 1303 1321 conf->interlace = NGX_CONF_UNSET; 1322 conf->use_scale_function = NGX_CONF_UNSET; 1304 1323 conf->buffer_size = NGX_CONF_UNSET_SIZE; 1305 1324 1306 1325 return conf; … … ngx_http_image_filter_merge_conf(ngx_con 1361 1380 1362 1381 ngx_conf_merge_value(conf->interlace, prev->interlace, 0); 1363 1382 1383 ngx_conf_merge_value(conf->use_scale_function, prev->use_scale_function, 0); 1384 1364 1385 ngx_conf_merge_size_value(conf->buffer_size, prev->buffer_size, 1365 1386 1 * 1024 * 1024); 1366 1387
