@@ -936,10 +936,10 @@ ngx_http_image_resize(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx)
936
936
{
937
937
int sx , sy , dx , dy , ox , oy , ax , ay , size ,
938
938
colors , palette , transparent , sharpen ,
939
- red , green , blue , t ,
939
+ red , green , blue , t , scale_max ,
940
940
offset_x , offset_y ;
941
941
u_char * out ;
942
- double scale_max , ratio , ratio_h ;
942
+ double ratio , ratio_h ;
943
943
ngx_buf_t * b ;
944
944
ngx_uint_t resize ;
945
945
gdImagePtr src , dst ;
@@ -952,10 +952,11 @@ ngx_http_image_resize(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx)
952
952
return NULL ;
953
953
}
954
954
955
- sx = gdImageSX (src );
956
- sy = gdImageSY (src );
957
-
958
- conf = ngx_http_get_module_loc_conf (r , ngx_http_image_filter_module );
955
+ sx = gdImageSX (src );
956
+ sy = gdImageSY (src );
957
+ conf = ngx_http_get_module_loc_conf (r , ngx_http_image_filter_module );
958
+ scale_max = (int ) conf -> scale_max ;
959
+ ratio = 1 ;
959
960
960
961
if (!ctx -> force
961
962
&& ctx -> angle == 0
@@ -989,61 +990,61 @@ ngx_http_image_resize(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx)
989
990
990
991
transparent :
991
992
992
- // ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "FUNC resize started \n");
993
+ if ((int )ctx -> max_width > 0 ) {
994
+ ratio = ((double ) ctx -> max_width / (double ) sx );
995
+ }
993
996
994
- // pre-resize if using scale
995
- if (conf -> scale_max > 1 ) {
996
- scale_max = (double ) conf -> scale_max ;
997
- ratio = ((double ) ctx -> max_width / (double ) sx );
998
- ratio_h = ((double ) ctx -> max_height / (double ) sy );
999
- if (ratio_h > ratio ) {
1000
- ratio = ratio_h ;
1001
- }
997
+ if ((int )ctx -> max_height > 0 ) {
998
+ ratio_h = ((double ) ctx -> max_height / (double ) sy );
999
+ if (ratio_h > ratio ) {
1000
+ ratio = ratio_h ;
1001
+ }
1002
+ }
1002
1003
1003
- if (ratio > scale_max ) {
1004
- ratio = scale_max ;
1004
+ // pre-resize if using scale and required a larger image
1005
+ if (scale_max > 1 ) {
1006
+ if (ratio > 1 ) {
1007
+ // ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "scale max = %d, %d \n", scale_max, scale_max);
1008
+ // ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "scale ratio = %d, %d \n", ratio, ratio);
1009
+
1010
+ if (ratio > (double ) scale_max ) {
1011
+ ratio = (double ) scale_max ;
1005
1012
}
1006
1013
1007
- //ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "scale ratio = %d, %d \n",
1008
- // ratio, ratio);
1014
+ /*
1015
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "width max = %d, %d \n", ctx->max_width, ctx->max_width);
1016
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "width img = %d, %d \n", sx, sx);
1017
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "height max = %d, %d \n", ctx->max_height, ctx->max_height);
1018
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "height img = %d, %d \n", sy, sy);
1019
+ */
1020
+
1021
+ // ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "scale %d, %d \n", ratio, ratio);
1022
+ dst = ngx_http_image_new (r , sx * ratio , sy * ratio , palette );
1009
1023
1010
- //ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "scale mw = %d, %d \n",
1011
- // ctx->max_width, ctx->max_width);
1012
-
1013
- //ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "scale mw = %d, %d \n",
1014
- // sx, sx);
1015
-
1016
- // if source is smaller, enlarge it
1017
- // resize to smaller can be handled later
1018
- if (ratio > 1 ) {
1019
- // ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "scale %d, %d \n", ratio, ratio);
1020
- dst = ngx_http_image_new (r , sx * ratio , sy * ratio , palette );
1021
-
1022
- if (dst == NULL ) {
1023
- gdImageDestroy (src );
1024
- return NULL ;
1025
- }
1026
-
1027
- if (transparent == -1 ) {
1028
- gdImageSaveAlpha (src , 1 );
1029
- gdImageColorTransparent (src , -1 );
1030
-
1031
- if (colors == 0 )
1032
- {
1033
- gdImageAlphaBlending (dst , 0 );
1034
- gdImageSaveAlpha (dst , 1 );
1035
- } else {
1036
- gdImageTrueColorToPalette (dst , 1 , 256 );
1037
- }
1038
- }
1039
-
1040
- my_resize (src , dst );
1041
- // set the new original
1042
- gdImageDestroy (src );
1043
- src = dst ;
1044
- sx = gdImageSX (src );
1045
- sy = gdImageSY (src );
1024
+ if (dst == NULL ) {
1025
+ gdImageDestroy (src );
1026
+ return NULL ;
1046
1027
}
1028
+
1029
+ if (transparent == -1 ) {
1030
+ gdImageSaveAlpha (src , 1 );
1031
+ gdImageColorTransparent (src , -1 );
1032
+
1033
+ if (colors == 0 ) {
1034
+ gdImageAlphaBlending (dst , 0 );
1035
+ gdImageSaveAlpha (dst , 1 );
1036
+ } else {
1037
+ gdImageTrueColorToPalette (dst , 1 , 256 );
1038
+ }
1039
+ }
1040
+
1041
+ my_resize (src , dst );
1042
+ // set the new original
1043
+ gdImageDestroy (src );
1044
+ src = dst ;
1045
+ sx = gdImageSX (src );
1046
+ sy = gdImageSY (src );
1047
+ }
1047
1048
}
1048
1049
1049
1050
gdImageColorTransparent (src , -1 );
0 commit comments