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