@@ -940,7 +940,7 @@ ngx_http_image_resize(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx)
940
940
red , green , blue , t ,
941
941
offset_x , offset_y ;
942
942
u_char * out ;
943
- double ratio_max , ratio ;
943
+ double ratio_max , ratio , ratio_h ;
944
944
ngx_buf_t * b ;
945
945
ngx_uint_t resize ;
946
946
gdImagePtr src , dst ;
@@ -992,55 +992,63 @@ ngx_http_image_resize(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx)
992
992
993
993
// ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "FUNC resize started \n");
994
994
995
- // pre-resize if using method2
995
+ // pre-resize if using scale
996
996
if (conf -> filter == NGX_HTTP_IMAGE_SCALE ) {
997
997
conf -> filter = NGX_HTTP_IMAGE_RESIZE ;
998
998
// don't allow bigger than double the size?
999
999
ratio_max = (double ) conf -> ratio_max ;
1000
1000
ratio = ((double ) ctx -> max_width / (double ) sx );
1001
+ ratio_h = ((double ) ctx -> max_height / (double ) sy );
1002
+ if (ratio_h > ratio ) {
1003
+ ratio = ratio_h ;
1004
+ }
1005
+
1001
1006
if (ratio > ratio_max ) {
1002
1007
ratio = ratio_max ;
1003
1008
}
1004
1009
1005
- //ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "resize2 ratio = %d, %d \n",
1010
+ //ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "scale ratio = %d, %d \n",
1006
1011
// ratio, ratio);
1007
1012
1008
- //ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "resize2 mw = %d, %d \n",
1013
+ //ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "scale mw = %d, %d \n",
1009
1014
// ctx->max_width, ctx->max_width);
1010
1015
1011
- //ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "resize2 mw = %d, %d \n",
1016
+ //ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "scale mw = %d, %d \n",
1012
1017
// sx, sx);
1013
1018
1014
1019
// if source is smaller, enlarge it
1015
1020
// resize to smaller can be handled later
1016
1021
if (ratio > 1 ) {
1017
- // ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "FUNC resize2 here %d, %d \n", ratio, ratio);
1018
-
1019
- dst = gdImageCreateTrueColor (sx * ratio , sy * ratio );
1022
+ // ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "scale %d, %d \n", ratio, ratio);
1023
+ dst = ngx_http_image_new (r , sx * ratio , sy * ratio , palette );
1024
+
1025
+ if (dst == NULL ) {
1026
+ gdImageDestroy (src );
1027
+ return NULL ;
1028
+ }
1020
1029
1021
1030
if (transparent == -1 ) {
1022
1031
gdImageSaveAlpha (src , 1 );
1023
1032
gdImageColorTransparent (src , -1 );
1024
1033
1025
1034
if (colors == 0 )
1026
1035
{
1027
- gdImageAlphaBlending (dst , 0 );
1028
- gdImageSaveAlpha (dst , 1 );
1036
+ gdImageAlphaBlending (dst , 0 );
1037
+ gdImageSaveAlpha (dst , 1 );
1029
1038
} else {
1030
- gdImageTrueColorToPalette (dst , 1 , 256 );
1039
+ gdImageTrueColorToPalette (dst , 1 , 256 );
1031
1040
}
1032
1041
}
1033
1042
1034
1043
my_resize (src , dst );
1035
1044
// set the new original
1036
1045
gdImageDestroy (src );
1037
1046
src = dst ;
1047
+ sx = gdImageSX (src );
1048
+ sy = gdImageSY (src );
1038
1049
}
1039
1050
}
1040
1051
1041
- sx = gdImageSX (src );
1042
- sy = gdImageSY (src );
1043
-
1044
1052
gdImageColorTransparent (src , -1 );
1045
1053
1046
1054
dx = sx ;
0 commit comments