@@ -1869,20 +1869,21 @@ PHP_FUNCTION(imagexbm)
1869
1869
zval * imgind ;
1870
1870
char * file = NULL ;
1871
1871
size_t file_len = 0 ;
1872
- zend_long foreground_color = -1 ;
1872
+ zend_long foreground_color ;
1873
+ zend_bool foreground_color_is_null = 1 ;
1873
1874
gdImagePtr im ;
1874
1875
int argc = ZEND_NUM_ARGS ();
1875
1876
int i ;
1876
1877
gdIOCtx * ctx = NULL ;
1877
1878
php_stream * stream ;
1878
1879
1879
- if (zend_parse_parameters (argc , "Op!|l" , & imgind , gd_image_ce , & file , & file_len , & foreground_color ) == FAILURE ) {
1880
+ if (zend_parse_parameters (argc , "Op!|l! " , & imgind , gd_image_ce , & file , & file_len , & foreground_color , & foreground_color_is_null ) == FAILURE ) {
1880
1881
RETURN_THROWS ();
1881
1882
}
1882
1883
1883
1884
im = php_gd_libgdimageptr_from_zval_p (imgind );
1884
1885
1885
- if (argc > 1 && file != NULL ) {
1886
+ if (file != NULL ) {
1886
1887
stream = php_stream_open_wrapper (file , "wb" , REPORT_ERRORS |IGNORE_PATH |IGNORE_URL_WIN , NULL );
1887
1888
if (stream == NULL ) {
1888
1889
RETURN_FALSE ;
@@ -1893,10 +1894,13 @@ PHP_FUNCTION(imagexbm)
1893
1894
ctx = create_output_context ();
1894
1895
}
1895
1896
1896
- if (argc < 3 ) {
1897
+ if (foreground_color_is_null ) {
1897
1898
for (i = 0 ; i < gdImageColorsTotal (im ); i ++ ) {
1898
- if (!gdImageRed (im , i ) && !gdImageGreen (im , i ) && !gdImageBlue (im , i )) break ;
1899
+ if (!gdImageRed (im , i ) && !gdImageGreen (im , i ) && !gdImageBlue (im , i )) {
1900
+ break ;
1901
+ }
1899
1902
}
1903
+
1900
1904
foreground_color = i ;
1901
1905
}
1902
1906
@@ -1946,20 +1950,20 @@ PHP_FUNCTION(imagejpeg)
1946
1950
PHP_FUNCTION (imagewbmp )
1947
1951
{
1948
1952
zval * imgind ;
1949
- zend_long foreground_color = -1 ;
1953
+ zend_long foreground_color ;
1954
+ zend_long foreground_color_is_null = 1 ;
1950
1955
gdImagePtr im ;
1951
- int argc = ZEND_NUM_ARGS ();
1952
1956
int i ;
1953
1957
gdIOCtx * ctx = NULL ;
1954
1958
zval * to_zval = NULL ;
1955
1959
1956
- if (zend_parse_parameters (argc , "O|z!l" , & imgind , gd_image_ce , & to_zval , & foreground_color ) == FAILURE ) {
1960
+ if (zend_parse_parameters (ZEND_NUM_ARGS () , "O|z!l! " , & imgind , gd_image_ce , & to_zval , & foreground_color ) == FAILURE ) {
1957
1961
RETURN_THROWS ();
1958
1962
}
1959
1963
1960
1964
im = php_gd_libgdimageptr_from_zval_p (imgind );
1961
1965
1962
- if (argc > 1 && to_zval != NULL ) {
1966
+ if (to_zval != NULL ) {
1963
1967
ctx = create_stream_context_from_zval (to_zval );
1964
1968
if (!ctx ) {
1965
1969
RETURN_FALSE ;
@@ -1968,10 +1972,11 @@ PHP_FUNCTION(imagewbmp)
1968
1972
ctx = create_output_context ();
1969
1973
}
1970
1974
1971
- if (argc < 3 ) {
1975
+ if (foreground_color_is_null ) {
1972
1976
for (i = 0 ; i < gdImageColorsTotal (im ); i ++ ) {
1973
- if (!gdImageRed (im , i ) && !gdImageGreen (im , i ) && !gdImageBlue (im , i ))
1977
+ if (!gdImageRed (im , i ) && !gdImageGreen (im , i ) && !gdImageBlue (im , i )) {
1974
1978
break ;
1979
+ }
1975
1980
}
1976
1981
1977
1982
foreground_color = i ;
@@ -2006,17 +2011,16 @@ PHP_FUNCTION(imagebmp)
2006
2011
zval * imgind ;
2007
2012
zend_bool compressed = 1 ;
2008
2013
gdImagePtr im ;
2009
- int argc = ZEND_NUM_ARGS ();
2010
2014
gdIOCtx * ctx = NULL ;
2011
2015
zval * to_zval = NULL ;
2012
2016
2013
- if (zend_parse_parameters (argc , "O|z!b" , & imgind , gd_image_ce , & to_zval , & compressed ) == FAILURE ) {
2017
+ if (zend_parse_parameters (ZEND_NUM_ARGS () , "O|z!b" , & imgind , gd_image_ce , & to_zval , & compressed ) == FAILURE ) {
2014
2018
RETURN_THROWS ();
2015
2019
}
2016
2020
2017
2021
im = php_gd_libgdimageptr_from_zval_p (imgind );
2018
2022
2019
- if (argc > 1 && to_zval != NULL ) {
2023
+ if (to_zval != NULL ) {
2020
2024
ctx = create_stream_context_from_zval (to_zval );
2021
2025
if (!ctx ) {
2022
2026
RETURN_FALSE ;
@@ -2555,16 +2559,16 @@ PHP_FUNCTION(imagecolortransparent)
2555
2559
{
2556
2560
zval * IM ;
2557
2561
zend_long COL = 0 ;
2562
+ zend_bool COL_IS_NULL = 1 ;
2558
2563
gdImagePtr im ;
2559
- int argc = ZEND_NUM_ARGS ();
2560
2564
2561
- if (zend_parse_parameters (argc , "O|l" , & IM , gd_image_ce , & COL ) == FAILURE ) {
2565
+ if (zend_parse_parameters (ZEND_NUM_ARGS () , "O|l! " , & IM , gd_image_ce , & COL , & COL_IS_NULL ) == FAILURE ) {
2562
2566
RETURN_THROWS ();
2563
2567
}
2564
2568
2565
2569
im = php_gd_libgdimageptr_from_zval_p (IM );
2566
2570
2567
- if (argc > 1 ) {
2571
+ if (! COL_IS_NULL ) {
2568
2572
gdImageColorTransparent (im , COL );
2569
2573
}
2570
2574
@@ -2576,17 +2580,17 @@ PHP_FUNCTION(imagecolortransparent)
2576
2580
PHP_FUNCTION (imageinterlace )
2577
2581
{
2578
2582
zval * IM ;
2579
- int argc = ZEND_NUM_ARGS ();
2580
2583
zend_long INT = 0 ;
2584
+ zend_bool INT_IS_NULL = 1 ;
2581
2585
gdImagePtr im ;
2582
2586
2583
- if (zend_parse_parameters (argc , "O|l" , & IM , gd_image_ce , & INT ) == FAILURE ) {
2587
+ if (zend_parse_parameters (ZEND_NUM_ARGS () , "O|l! " , & IM , gd_image_ce , & INT , & INT_IS_NULL ) == FAILURE ) {
2584
2588
RETURN_THROWS ();
2585
2589
}
2586
2590
2587
2591
im = php_gd_libgdimageptr_from_zval_p (IM );
2588
2592
2589
- if (argc > 1 ) {
2593
+ if (! INT_IS_NULL ) {
2590
2594
gdImageInterlace (im , INT );
2591
2595
}
2592
2596
@@ -2603,15 +2607,16 @@ static void php_imagepolygon(INTERNAL_FUNCTION_PARAMETERS, int filled)
2603
2607
{
2604
2608
zval * IM , * POINTS ;
2605
2609
zend_long NPOINTS , COL ;
2610
+ zend_bool COL_IS_NULL = 1 ;
2606
2611
zval * var = NULL ;
2607
2612
gdImagePtr im ;
2608
2613
gdPointPtr points ;
2609
2614
int npoints , col , nelem , i ;
2610
2615
2611
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "Oal|l" , & IM , gd_image_ce , & POINTS , & NPOINTS , & COL ) == FAILURE ) {
2616
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "Oal|l! " , & IM , gd_image_ce , & POINTS , & NPOINTS , & COL , & COL_IS_NULL ) == FAILURE ) {
2612
2617
RETURN_THROWS ();
2613
2618
}
2614
- if (ZEND_NUM_ARGS () == 3 ) {
2619
+ if (COL_IS_NULL ) {
2615
2620
COL = NPOINTS ;
2616
2621
NPOINTS = zend_hash_num_elements (Z_ARRVAL_P (POINTS ));
2617
2622
if (NPOINTS % 2 != 0 ) {
@@ -3733,7 +3738,7 @@ PHP_FUNCTION(imageaffine)
3733
3738
int i , nelems ;
3734
3739
zval * zval_affine_elem = NULL ;
3735
3740
3736
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "Oa|a" , & IM , gd_image_ce , & z_affine , & z_rect ) == FAILURE ) {
3741
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "Oa|a! " , & IM , gd_image_ce , & z_affine , & z_rect ) == FAILURE ) {
3737
3742
RETURN_THROWS ();
3738
3743
}
3739
3744
@@ -3856,7 +3861,7 @@ PHP_FUNCTION(imageaffinematrixget)
3856
3861
double angle ;
3857
3862
3858
3863
if (!options ) {
3859
- zend_argument_type_error (2 , "must be of type int|double when using rotate or shear" );
3864
+ zend_argument_type_error (2 , "must be of type int|float when using rotate or shear" );
3860
3865
RETURN_THROWS ();
3861
3866
}
3862
3867
@@ -4003,26 +4008,29 @@ PHP_FUNCTION(imageresolution)
4003
4008
{
4004
4009
zval * IM ;
4005
4010
gdImagePtr im ;
4006
- zend_long res_x = GD_RESOLUTION , res_y = GD_RESOLUTION ;
4011
+ zend_long res_x , res_y ;
4012
+ zend_bool res_x_is_null = 1 , res_y_is_null = 1 ;
4007
4013
4008
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "O|ll " , & IM , gd_image_ce , & res_x , & res_y ) == FAILURE ) {
4014
+ 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
4015
RETURN_THROWS ();
4010
4016
}
4011
4017
4012
4018
im = php_gd_libgdimageptr_from_zval_p (IM );
4013
4019
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 ));
4020
+ if (!res_x_is_null && !res_y_is_null ) {
4021
+ gdImageSetResolution (im , res_x , res_y );
4022
+ RETURN_TRUE ;
4023
+ } else if (!res_x_is_null && res_y_is_null ) {
4024
+ gdImageSetResolution (im , res_x , res_x );
4025
+ RETURN_TRUE ;
4026
+ } else if (res_x_is_null && !res_y_is_null ) {
4027
+ gdImageSetResolution (im , res_y , res_y );
4028
+ RETURN_TRUE ;
4025
4029
}
4030
+
4031
+ array_init (return_value );
4032
+ add_next_index_long (return_value , gdImageResolutionX (im ));
4033
+ add_next_index_long (return_value , gdImageResolutionY (im ));
4026
4034
}
4027
4035
/* }}} */
4028
4036
@@ -4156,7 +4164,11 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
4156
4164
gdIOCtx * ctx = NULL ;
4157
4165
zval * to_zval = NULL ;
4158
4166
4159
- if (image_type == PHP_GDIMG_TYPE_PNG ) {
4167
+ if (image_type == PHP_GDIMG_TYPE_GIF ) {
4168
+ if (zend_parse_parameters (argc , "O|z" , & imgind , gd_image_ce , & to_zval ) == FAILURE ) {
4169
+ RETURN_THROWS ();
4170
+ }
4171
+ } else if (image_type == PHP_GDIMG_TYPE_PNG ) {
4160
4172
if (zend_parse_parameters (argc , "O|z!ll" , & imgind , gd_image_ce , & to_zval , & quality , & basefilter ) == FAILURE ) {
4161
4173
RETURN_THROWS ();
4162
4174
}
@@ -4168,7 +4180,7 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
4168
4180
4169
4181
im = php_gd_libgdimageptr_from_zval_p (imgind );
4170
4182
4171
- if (argc > 1 && to_zval != NULL ) {
4183
+ if (to_zval != NULL ) {
4172
4184
ctx = create_stream_context_from_zval (to_zval );
4173
4185
if (!ctx ) {
4174
4186
RETURN_FALSE ;
@@ -4190,16 +4202,6 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
4190
4202
case PHP_GDIMG_TYPE_PNG :
4191
4203
(* func_p )(im , ctx , (int ) quality , (int ) basefilter );
4192
4204
break ;
4193
- case PHP_GDIMG_TYPE_WBM :
4194
- if (argc < 3 ) {
4195
- for (i = 0 ; i < gdImageColorsTotal (im ); i ++ ) {
4196
- if (!gdImageRed (im , i ) && !gdImageGreen (im , i ) && !gdImageBlue (im , i )) break ;
4197
- }
4198
- quality = (int ) i ;
4199
- }
4200
-
4201
- (* func_p )(im , (int ) quality , ctx );
4202
- break ;
4203
4205
case PHP_GDIMG_TYPE_GIF :
4204
4206
(* func_p )(im , ctx );
4205
4207
break ;
0 commit comments