@@ -155,10 +155,6 @@ typedef struct _gd_ext_image_object {
155
155
156
156
static zend_object_handlers php_gd_image_object_handlers ;
157
157
158
- static const zend_function_entry gd_image_object_methods [] = {
159
- PHP_FE_END
160
- };
161
-
162
158
static zend_function * php_gd_image_object_get_constructor (zend_object * object )
163
159
{
164
160
zend_throw_error (NULL , "You cannot initialize a GdImage object except through helper functions" );
@@ -221,7 +217,7 @@ void php_gd_assign_libgdimageptr_as_extgdimage(zval *val, gdImagePtr image)
221
217
static void php_gd_object_minit_helper ()
222
218
{
223
219
zend_class_entry ce ;
224
- INIT_CLASS_ENTRY (ce , "GdImage" , gd_image_object_methods );
220
+ INIT_CLASS_ENTRY (ce , "GdImage" , class_GdImage_methods );
225
221
gd_image_ce = zend_register_internal_class (& ce );
226
222
gd_image_ce -> ce_flags |= ZEND_ACC_FINAL ;
227
223
gd_image_ce -> create_object = php_gd_image_object_create ;
@@ -2542,16 +2538,17 @@ PHP_FUNCTION(imagecolortransparent)
2542
2538
{
2543
2539
zval * IM ;
2544
2540
zend_long COL = 0 ;
2541
+ zend_bool COL_IS_NULL = 1 ;
2545
2542
gdImagePtr im ;
2546
2543
int argc = ZEND_NUM_ARGS ();
2547
2544
2548
- if (zend_parse_parameters (argc , "O|l" , & IM , gd_image_ce , & COL ) == FAILURE ) {
2545
+ if (zend_parse_parameters (argc , "O|l! " , & IM , gd_image_ce , & COL , & COL_IS_NULL ) == FAILURE ) {
2549
2546
RETURN_THROWS ();
2550
2547
}
2551
2548
2552
2549
im = php_gd_libgdimageptr_from_zval_p (IM );
2553
2550
2554
- if (argc > 1 ) {
2551
+ if (! COL_IS_NULL ) {
2555
2552
gdImageColorTransparent (im , COL );
2556
2553
}
2557
2554
@@ -2566,15 +2563,16 @@ PHP_FUNCTION(imageinterlace)
2566
2563
zval * IM ;
2567
2564
int argc = ZEND_NUM_ARGS ();
2568
2565
zend_long INT = 0 ;
2566
+ zend_bool INT_IS_NULL = 1 ;
2569
2567
gdImagePtr im ;
2570
2568
2571
- if (zend_parse_parameters (argc , "O|l" , & IM , gd_image_ce , & INT ) == FAILURE ) {
2569
+ if (zend_parse_parameters (argc , "O|l! " , & IM , gd_image_ce , & INT , & INT_IS_NULL ) == FAILURE ) {
2572
2570
RETURN_THROWS ();
2573
2571
}
2574
2572
2575
2573
im = php_gd_libgdimageptr_from_zval_p (IM );
2576
2574
2577
- if (argc > 1 ) {
2575
+ if (! INT_IS_NULL ) {
2578
2576
gdImageInterlace (im , INT );
2579
2577
}
2580
2578
@@ -2591,15 +2589,16 @@ static void php_imagepolygon(INTERNAL_FUNCTION_PARAMETERS, int filled)
2591
2589
{
2592
2590
zval * IM , * POINTS ;
2593
2591
zend_long NPOINTS , COL ;
2592
+ zend_bool COL_IS_NULL = 1 ;
2594
2593
zval * var = NULL ;
2595
2594
gdImagePtr im ;
2596
2595
gdPointPtr points ;
2597
2596
int npoints , col , nelem , i ;
2598
2597
2599
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "Oal|l" , & IM , gd_image_ce , & POINTS , & NPOINTS , & COL ) == FAILURE ) {
2598
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "Oal|l! " , & IM , gd_image_ce , & POINTS , & NPOINTS , & COL , & COL_IS_NULL ) == FAILURE ) {
2600
2599
RETURN_THROWS ();
2601
2600
}
2602
- if (ZEND_NUM_ARGS () == 3 ) {
2601
+ if (COL_IS_NULL ) {
2603
2602
COL = NPOINTS ;
2604
2603
NPOINTS = zend_hash_num_elements (Z_ARRVAL_P (POINTS ));
2605
2604
if (NPOINTS % 2 != 0 ) {
@@ -3752,7 +3751,7 @@ PHP_FUNCTION(imageaffine)
3752
3751
int i , nelems ;
3753
3752
zval * zval_affine_elem = NULL ;
3754
3753
3755
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "Oa|a" , & IM , gd_image_ce , & z_affine , & z_rect ) == FAILURE ) {
3754
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "Oa|a! " , & IM , gd_image_ce , & z_affine , & z_rect ) == FAILURE ) {
3756
3755
RETURN_THROWS ();
3757
3756
}
3758
3757
@@ -3876,7 +3875,7 @@ PHP_FUNCTION(imageaffinematrixget)
3876
3875
double angle ;
3877
3876
3878
3877
if (!options ) {
3879
- zend_argument_type_error (2 , "must be of type int|double when using rotate or shear" );
3878
+ zend_argument_type_error (2 , "must be of type int|float when using rotate or shear" );
3880
3879
RETURN_THROWS ();
3881
3880
}
3882
3881
@@ -4027,26 +4026,26 @@ PHP_FUNCTION(imageresolution)
4027
4026
{
4028
4027
zval * IM ;
4029
4028
gdImagePtr im ;
4030
- zend_long res_x = GD_RESOLUTION , res_y = GD_RESOLUTION ;
4029
+ zend_long res_x , res_y ;
4030
+ zend_bool res_x_is_null = 1 , res_y_is_null = 1 ;
4031
4031
4032
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "O|ll " , & IM , gd_image_ce , & res_x , & res_y ) == FAILURE ) {
4032
+ 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 ) {
4033
4033
RETURN_THROWS ();
4034
4034
}
4035
4035
4036
4036
im = php_gd_libgdimageptr_from_zval_p (IM );
4037
4037
4038
- switch (ZEND_NUM_ARGS ()) {
4039
- case 3 :
4040
- gdImageSetResolution (im , res_x , res_y );
4041
- RETURN_TRUE ;
4042
- case 2 :
4043
- gdImageSetResolution (im , res_x , res_x );
4044
- RETURN_TRUE ;
4045
- default :
4046
- array_init (return_value );
4047
- add_next_index_long (return_value , gdImageResolutionX (im ));
4048
- add_next_index_long (return_value , gdImageResolutionY (im ));
4038
+ if (!res_x_is_null && !res_y_is_null ) {
4039
+ gdImageSetResolution (im , res_x , res_y );
4040
+ RETURN_TRUE ;
4041
+ } else if (!res_x_is_null && res_y_is_null ) {
4042
+ gdImageSetResolution (im , res_x , res_x );
4043
+ RETURN_TRUE ;
4049
4044
}
4045
+
4046
+ array_init (return_value );
4047
+ add_next_index_long (return_value , gdImageResolutionX (im ));
4048
+ add_next_index_long (return_value , gdImageResolutionY (im ));
4050
4049
}
4051
4050
/* }}} */
4052
4051
@@ -4124,9 +4123,8 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
4124
4123
char * file = NULL ;
4125
4124
size_t file_len = 0 ;
4126
4125
zend_long quality , basefilter ;
4127
- zend_bool compressed = 1 ;
4126
+ zend_bool compressed = 1 , quality_is_null = 1 , basefilter_is_null = 1 ;
4128
4127
gdImagePtr im ;
4129
- int argc = ZEND_NUM_ARGS ();
4130
4128
int q = -1 , i ;
4131
4129
int f = -1 ;
4132
4130
gdIOCtx * ctx = NULL ;
@@ -4139,12 +4137,14 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
4139
4137
*/
4140
4138
switch (image_type ) {
4141
4139
case PHP_GDIMG_TYPE_XBM :
4142
- if (zend_parse_parameters (argc , "Op!|ll" , & imgind , gd_image_ce , & file , & file_len , & quality , & basefilter ) == FAILURE ) {
4140
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "Op!|l!l!" ,
4141
+ & imgind , gd_image_ce , & file , & file_len , & quality , & quality_is_null , & basefilter , & basefilter_is_null
4142
+ ) == FAILURE ) {
4143
4143
RETURN_THROWS ();
4144
4144
}
4145
4145
break ;
4146
4146
case PHP_GDIMG_TYPE_BMP :
4147
- if (zend_parse_parameters (argc , "O|z!b" , & imgind , gd_image_ce , & to_zval , & compressed ) == FAILURE ) {
4147
+ if (zend_parse_parameters (ZEND_NUM_ARGS () , "O|z!b" , & imgind , gd_image_ce , & to_zval , & compressed ) == FAILURE ) {
4148
4148
RETURN_THROWS ();
4149
4149
}
4150
4150
break ;
@@ -4155,21 +4155,26 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
4155
4155
* PHP_GDIMG_TYPE_WBM
4156
4156
* PHP_GDIMG_TYPE_WEBP
4157
4157
* */
4158
- if (zend_parse_parameters (argc , "O|z!ll" , & imgind , gd_image_ce , & to_zval , & quality , & basefilter ) == FAILURE ) {
4158
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "O|z!l!l!" ,
4159
+ & imgind , gd_image_ce , & to_zval , & quality , & quality_is_null , & basefilter , & basefilter_is_null
4160
+ ) == FAILURE ) {
4159
4161
RETURN_THROWS ();
4160
4162
}
4161
4163
}
4162
4164
4163
4165
im = php_gd_libgdimageptr_from_zval_p (imgind );
4164
4166
4165
- if (image_type != PHP_GDIMG_TYPE_BMP && argc >= 3 ) {
4166
- q = quality ; /* or colorindex for foreground of BW images (defaults to black) */
4167
- if (argc == 4 ) {
4167
+ if (image_type != PHP_GDIMG_TYPE_BMP ) {
4168
+ if (!quality_is_null ) {
4169
+ q = quality ; /* or colorindex for foreground of BW images (defaults to black) */
4170
+ }
4171
+
4172
+ if (!basefilter_is_null ) {
4168
4173
f = basefilter ;
4169
4174
}
4170
4175
}
4171
4176
4172
- if (argc > 1 && to_zval != NULL ) {
4177
+ if (to_zval != NULL ) {
4173
4178
if (Z_TYPE_P (to_zval ) == IS_RESOURCE ) {
4174
4179
php_stream_from_zval_no_verify (stream , to_zval );
4175
4180
if (stream == NULL ) {
@@ -4190,7 +4195,7 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
4190
4195
php_error_docref (NULL , E_WARNING , "Invalid 2nd parameter, it must a filename or a stream" );
4191
4196
RETURN_FALSE ;
4192
4197
}
4193
- } else if (argc > 1 && file != NULL ) {
4198
+ } else if (file != NULL ) {
4194
4199
stream = php_stream_open_wrapper (file , "wb" , REPORT_ERRORS |IGNORE_PATH |IGNORE_URL_WIN , NULL );
4195
4200
if (stream == NULL ) {
4196
4201
RETURN_FALSE ;
@@ -4229,7 +4234,7 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
4229
4234
break ;
4230
4235
case PHP_GDIMG_TYPE_XBM :
4231
4236
case PHP_GDIMG_TYPE_WBM :
4232
- if (argc < 3 ) {
4237
+ if (quality_is_null ) {
4233
4238
for (i = 0 ; i < gdImageColorsTotal (im ); i ++ ) {
4234
4239
if (!gdImageRed (im , i ) && !gdImageGreen (im , i ) && !gdImageBlue (im , i )) break ;
4235
4240
}
0 commit comments