@@ -1948,18 +1948,17 @@ PHP_FUNCTION(imagewbmp)
1948
1948
zval * imgind ;
1949
1949
zend_long foreground_color = -1 ;
1950
1950
gdImagePtr im ;
1951
- int argc = ZEND_NUM_ARGS ();
1952
1951
int i ;
1953
1952
gdIOCtx * ctx = NULL ;
1954
1953
zval * to_zval = NULL ;
1955
1954
1956
- if (zend_parse_parameters (argc , "O|z!l" , & imgind , gd_image_ce , & to_zval , & foreground_color ) == FAILURE ) {
1955
+ if (zend_parse_parameters (ZEND_NUM_ARGS () , "O|z!l" , & imgind , gd_image_ce , & to_zval , & foreground_color ) == FAILURE ) {
1957
1956
RETURN_THROWS ();
1958
1957
}
1959
1958
1960
1959
im = php_gd_libgdimageptr_from_zval_p (imgind );
1961
1960
1962
- if (argc > 1 && to_zval != NULL ) {
1961
+ if (to_zval != NULL ) {
1963
1962
ctx = create_stream_context_from_zval (to_zval );
1964
1963
if (!ctx ) {
1965
1964
RETURN_FALSE ;
@@ -1968,10 +1967,11 @@ PHP_FUNCTION(imagewbmp)
1968
1967
ctx = create_output_context ();
1969
1968
}
1970
1969
1971
- if (argc < 3 ) {
1970
+ if (foreground_color == -1 ) {
1972
1971
for (i = 0 ; i < gdImageColorsTotal (im ); i ++ ) {
1973
- if (!gdImageRed (im , i ) && !gdImageGreen (im , i ) && !gdImageBlue (im , i ))
1972
+ if (!gdImageRed (im , i ) && !gdImageGreen (im , i ) && !gdImageBlue (im , i )) {
1974
1973
break ;
1974
+ }
1975
1975
}
1976
1976
1977
1977
foreground_color = i ;
@@ -2006,17 +2006,16 @@ PHP_FUNCTION(imagebmp)
2006
2006
zval * imgind ;
2007
2007
zend_bool compressed = 1 ;
2008
2008
gdImagePtr im ;
2009
- int argc = ZEND_NUM_ARGS ();
2010
2009
gdIOCtx * ctx = NULL ;
2011
2010
zval * to_zval = NULL ;
2012
2011
2013
- if (zend_parse_parameters (argc , "O|z!b" , & imgind , gd_image_ce , & to_zval , & compressed ) == FAILURE ) {
2012
+ if (zend_parse_parameters (ZEND_NUM_ARGS () , "O|z!b" , & imgind , gd_image_ce , & to_zval , & compressed ) == FAILURE ) {
2014
2013
RETURN_THROWS ();
2015
2014
}
2016
2015
2017
2016
im = php_gd_libgdimageptr_from_zval_p (imgind );
2018
2017
2019
- if (argc > 1 && to_zval != NULL ) {
2018
+ if (to_zval != NULL ) {
2020
2019
ctx = create_stream_context_from_zval (to_zval );
2021
2020
if (!ctx ) {
2022
2021
RETURN_FALSE ;
@@ -2555,16 +2554,16 @@ PHP_FUNCTION(imagecolortransparent)
2555
2554
{
2556
2555
zval * IM ;
2557
2556
zend_long COL = 0 ;
2557
+ zend_bool COL_IS_NULL = 1 ;
2558
2558
gdImagePtr im ;
2559
- int argc = ZEND_NUM_ARGS ();
2560
2559
2561
- if (zend_parse_parameters (argc , "O|l" , & IM , gd_image_ce , & COL ) == FAILURE ) {
2560
+ if (zend_parse_parameters (ZEND_NUM_ARGS () , "O|l! " , & IM , gd_image_ce , & COL , & COL_IS_NULL ) == FAILURE ) {
2562
2561
RETURN_THROWS ();
2563
2562
}
2564
2563
2565
2564
im = php_gd_libgdimageptr_from_zval_p (IM );
2566
2565
2567
- if (argc > 1 ) {
2566
+ if (! COL_IS_NULL ) {
2568
2567
gdImageColorTransparent (im , COL );
2569
2568
}
2570
2569
@@ -2576,17 +2575,17 @@ PHP_FUNCTION(imagecolortransparent)
2576
2575
PHP_FUNCTION (imageinterlace )
2577
2576
{
2578
2577
zval * IM ;
2579
- int argc = ZEND_NUM_ARGS ();
2580
2578
zend_long INT = 0 ;
2579
+ zend_bool INT_IS_NULL = 1 ;
2581
2580
gdImagePtr im ;
2582
2581
2583
- if (zend_parse_parameters (argc , "O|l" , & IM , gd_image_ce , & INT ) == FAILURE ) {
2582
+ if (zend_parse_parameters (ZEND_NUM_ARGS () , "O|l! " , & IM , gd_image_ce , & INT , & INT_IS_NULL ) == FAILURE ) {
2584
2583
RETURN_THROWS ();
2585
2584
}
2586
2585
2587
2586
im = php_gd_libgdimageptr_from_zval_p (IM );
2588
2587
2589
- if (argc > 1 ) {
2588
+ if (! INT_IS_NULL ) {
2590
2589
gdImageInterlace (im , INT );
2591
2590
}
2592
2591
@@ -2603,15 +2602,16 @@ static void php_imagepolygon(INTERNAL_FUNCTION_PARAMETERS, int filled)
2603
2602
{
2604
2603
zval * IM , * POINTS ;
2605
2604
zend_long NPOINTS , COL ;
2605
+ zend_bool COL_IS_NULL = 1 ;
2606
2606
zval * var = NULL ;
2607
2607
gdImagePtr im ;
2608
2608
gdPointPtr points ;
2609
2609
int npoints , col , nelem , i ;
2610
2610
2611
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "Oal|l" , & IM , gd_image_ce , & POINTS , & NPOINTS , & COL ) == FAILURE ) {
2611
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "Oal|l! " , & IM , gd_image_ce , & POINTS , & NPOINTS , & COL , & COL_IS_NULL ) == FAILURE ) {
2612
2612
RETURN_THROWS ();
2613
2613
}
2614
- if (ZEND_NUM_ARGS () == 3 ) {
2614
+ if (COL_IS_NULL ) {
2615
2615
COL = NPOINTS ;
2616
2616
NPOINTS = zend_hash_num_elements (Z_ARRVAL_P (POINTS ));
2617
2617
if (NPOINTS % 2 != 0 ) {
@@ -3733,7 +3733,7 @@ PHP_FUNCTION(imageaffine)
3733
3733
int i , nelems ;
3734
3734
zval * zval_affine_elem = NULL ;
3735
3735
3736
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "Oa|a" , & IM , gd_image_ce , & z_affine , & z_rect ) == FAILURE ) {
3736
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "Oa|a! " , & IM , gd_image_ce , & z_affine , & z_rect ) == FAILURE ) {
3737
3737
RETURN_THROWS ();
3738
3738
}
3739
3739
@@ -3856,7 +3856,7 @@ PHP_FUNCTION(imageaffinematrixget)
3856
3856
double angle ;
3857
3857
3858
3858
if (!options ) {
3859
- zend_argument_type_error (2 , "must be of type int|double when using rotate or shear" );
3859
+ zend_argument_type_error (2 , "must be of type int|float when using rotate or shear" );
3860
3860
RETURN_THROWS ();
3861
3861
}
3862
3862
@@ -4003,26 +4003,29 @@ PHP_FUNCTION(imageresolution)
4003
4003
{
4004
4004
zval * IM ;
4005
4005
gdImagePtr im ;
4006
- zend_long res_x = GD_RESOLUTION , res_y = GD_RESOLUTION ;
4006
+ zend_long res_x , res_y ;
4007
+ zend_bool res_x_is_null = 1 , res_y_is_null = 1 ;
4007
4008
4008
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "O|ll " , & IM , gd_image_ce , & res_x , & res_y ) == FAILURE ) {
4009
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "O|l!l! " , & IM , gd_image_ce , & res_x , & res_x_is_null , & res_y , & res_y_is_null ) == FAILURE ) {
4009
4010
RETURN_THROWS ();
4010
4011
}
4011
4012
4012
4013
im = php_gd_libgdimageptr_from_zval_p (IM );
4013
4014
4014
- switch (ZEND_NUM_ARGS ()) {
4015
- case 3 :
4016
- gdImageSetResolution (im , res_x , res_y );
4017
- RETURN_TRUE ;
4018
- case 2 :
4019
- gdImageSetResolution (im , res_x , res_x );
4020
- RETURN_TRUE ;
4021
- default :
4022
- array_init (return_value );
4023
- add_next_index_long (return_value , gdImageResolutionX (im ));
4024
- add_next_index_long (return_value , gdImageResolutionY (im ));
4015
+ if (!res_x_is_null && !res_y_is_null ) {
4016
+ gdImageSetResolution (im , res_x , res_y );
4017
+ RETURN_TRUE ;
4018
+ } else if (!res_x_is_null && res_y_is_null ) {
4019
+ gdImageSetResolution (im , res_x , res_x );
4020
+ RETURN_TRUE ;
4021
+ } else if (res_x_is_null && !res_y_is_null ) {
4022
+ gdImageSetResolution (im , res_y , res_y );
4023
+ RETURN_TRUE ;
4025
4024
}
4025
+
4026
+ array_init (return_value );
4027
+ add_next_index_long (return_value , gdImageResolutionX (im ));
4028
+ add_next_index_long (return_value , gdImageResolutionY (im ));
4026
4029
}
4027
4030
/* }}} */
4028
4031
@@ -4156,7 +4159,11 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
4156
4159
gdIOCtx * ctx = NULL ;
4157
4160
zval * to_zval = NULL ;
4158
4161
4159
- if (image_type == PHP_GDIMG_TYPE_PNG ) {
4162
+ if (image_type == PHP_GDIMG_TYPE_GIF ) {
4163
+ if (zend_parse_parameters (argc , "O|z" , & imgind , gd_image_ce , & to_zval ) == FAILURE ) {
4164
+ RETURN_THROWS ();
4165
+ }
4166
+ } else if (image_type == PHP_GDIMG_TYPE_PNG ) {
4160
4167
if (zend_parse_parameters (argc , "O|z!ll" , & imgind , gd_image_ce , & to_zval , & quality , & basefilter ) == FAILURE ) {
4161
4168
RETURN_THROWS ();
4162
4169
}
@@ -4168,7 +4175,7 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
4168
4175
4169
4176
im = php_gd_libgdimageptr_from_zval_p (imgind );
4170
4177
4171
- if (argc > 1 && to_zval != NULL ) {
4178
+ if (to_zval != NULL ) {
4172
4179
ctx = create_stream_context_from_zval (to_zval );
4173
4180
if (!ctx ) {
4174
4181
RETURN_FALSE ;
@@ -4191,7 +4198,7 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
4191
4198
(* func_p )(im , ctx , (int ) quality , (int ) basefilter );
4192
4199
break ;
4193
4200
case PHP_GDIMG_TYPE_WBM :
4194
- if (argc < 3 ) {
4201
+ if (quality == -1 ) {
4195
4202
for (i = 0 ; i < gdImageColorsTotal (im ); i ++ ) {
4196
4203
if (!gdImageRed (im , i ) && !gdImageGreen (im , i ) && !gdImageBlue (im , i )) break ;
4197
4204
}
0 commit comments