@@ -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,16 @@ 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
- int argc = ZEND_NUM_ARGS ();
2547
2543
2548
- if (zend_parse_parameters (argc , "O|l" , & IM , gd_image_ce , & COL ) == FAILURE ) {
2544
+ if (zend_parse_parameters (ZEND_NUM_ARGS () , "O|l! " , & IM , gd_image_ce , & COL , & COL_IS_NULL ) == FAILURE ) {
2549
2545
RETURN_THROWS ();
2550
2546
}
2551
2547
2552
2548
im = php_gd_libgdimageptr_from_zval_p (IM );
2553
2549
2554
- if (argc > 1 ) {
2550
+ if (! COL_IS_NULL ) {
2555
2551
gdImageColorTransparent (im , COL );
2556
2552
}
2557
2553
@@ -2564,17 +2560,17 @@ PHP_FUNCTION(imagecolortransparent)
2564
2560
PHP_FUNCTION (imageinterlace )
2565
2561
{
2566
2562
zval * IM ;
2567
- int argc = ZEND_NUM_ARGS ();
2568
2563
zend_long INT = 0 ;
2564
+ zend_bool INT_IS_NULL = 1 ;
2569
2565
gdImagePtr im ;
2570
2566
2571
- if (zend_parse_parameters (argc , "O|l" , & IM , gd_image_ce , & INT ) == FAILURE ) {
2567
+ if (zend_parse_parameters (ZEND_NUM_ARGS () , "O|l! " , & IM , gd_image_ce , & INT , & INT_IS_NULL ) == FAILURE ) {
2572
2568
RETURN_THROWS ();
2573
2569
}
2574
2570
2575
2571
im = php_gd_libgdimageptr_from_zval_p (IM );
2576
2572
2577
- if (argc > 1 ) {
2573
+ if (! INT_IS_NULL ) {
2578
2574
gdImageInterlace (im , INT );
2579
2575
}
2580
2576
@@ -2591,15 +2587,16 @@ static void php_imagepolygon(INTERNAL_FUNCTION_PARAMETERS, int filled)
2591
2587
{
2592
2588
zval * IM , * POINTS ;
2593
2589
zend_long NPOINTS , COL ;
2590
+ zend_bool COL_IS_NULL = 1 ;
2594
2591
zval * var = NULL ;
2595
2592
gdImagePtr im ;
2596
2593
gdPointPtr points ;
2597
2594
int npoints , col , nelem , i ;
2598
2595
2599
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "Oal|l" , & IM , gd_image_ce , & POINTS , & NPOINTS , & COL ) == FAILURE ) {
2596
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "Oal|l! " , & IM , gd_image_ce , & POINTS , & NPOINTS , & COL , & COL_IS_NULL ) == FAILURE ) {
2600
2597
RETURN_THROWS ();
2601
2598
}
2602
- if (ZEND_NUM_ARGS () == 3 ) {
2599
+ if (COL_IS_NULL ) {
2603
2600
COL = NPOINTS ;
2604
2601
NPOINTS = zend_hash_num_elements (Z_ARRVAL_P (POINTS ));
2605
2602
if (NPOINTS % 2 != 0 ) {
@@ -3752,7 +3749,7 @@ PHP_FUNCTION(imageaffine)
3752
3749
int i , nelems ;
3753
3750
zval * zval_affine_elem = NULL ;
3754
3751
3755
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "Oa|a" , & IM , gd_image_ce , & z_affine , & z_rect ) == FAILURE ) {
3752
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "Oa|a! " , & IM , gd_image_ce , & z_affine , & z_rect ) == FAILURE ) {
3756
3753
RETURN_THROWS ();
3757
3754
}
3758
3755
@@ -3876,7 +3873,7 @@ PHP_FUNCTION(imageaffinematrixget)
3876
3873
double angle ;
3877
3874
3878
3875
if (!options ) {
3879
- zend_argument_type_error (2 , "must be of type int|double when using rotate or shear" );
3876
+ zend_argument_type_error (2 , "must be of type int|float when using rotate or shear" );
3880
3877
RETURN_THROWS ();
3881
3878
}
3882
3879
@@ -4027,26 +4024,29 @@ PHP_FUNCTION(imageresolution)
4027
4024
{
4028
4025
zval * IM ;
4029
4026
gdImagePtr im ;
4030
- zend_long res_x = GD_RESOLUTION , res_y = GD_RESOLUTION ;
4027
+ zend_long res_x , res_y ;
4028
+ zend_bool res_x_is_null = 1 , res_y_is_null = 1 ;
4031
4029
4032
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "O|ll " , & IM , gd_image_ce , & res_x , & res_y ) == FAILURE ) {
4030
+ 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
4031
RETURN_THROWS ();
4034
4032
}
4035
4033
4036
4034
im = php_gd_libgdimageptr_from_zval_p (IM );
4037
4035
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 ));
4036
+ if (!res_x_is_null && !res_y_is_null ) {
4037
+ gdImageSetResolution (im , res_x , res_y );
4038
+ RETURN_TRUE ;
4039
+ } else if (!res_x_is_null && res_y_is_null ) {
4040
+ gdImageSetResolution (im , res_x , res_x );
4041
+ RETURN_TRUE ;
4042
+ } else if (res_x_is_null && !res_y_is_null ) {
4043
+ gdImageSetResolution (im , res_y , res_y );
4044
+ RETURN_TRUE ;
4049
4045
}
4046
+
4047
+ array_init (return_value );
4048
+ add_next_index_long (return_value , gdImageResolutionX (im ));
4049
+ add_next_index_long (return_value , gdImageResolutionY (im ));
4050
4050
}
4051
4051
/* }}} */
4052
4052
@@ -4123,12 +4123,10 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
4123
4123
zval * imgind ;
4124
4124
char * file = NULL ;
4125
4125
size_t file_len = 0 ;
4126
- zend_long quality , basefilter ;
4126
+ zend_long quality = -1 , basefilter = -1 ;
4127
4127
zend_bool compressed = 1 ;
4128
4128
gdImagePtr im ;
4129
- int argc = ZEND_NUM_ARGS ();
4130
- int q = -1 , i ;
4131
- int f = -1 ;
4129
+ int i ;
4132
4130
gdIOCtx * ctx = NULL ;
4133
4131
zval * to_zval = NULL ;
4134
4132
php_stream * stream ;
@@ -4139,37 +4137,45 @@ 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" ,
4141
+ & imgind , gd_image_ce , & file , & file_len , & quality
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
+ RETURN_THROWS ();
4149
+ }
4150
+ break ;
4151
+ case PHP_GDIMG_TYPE_PNG :
4152
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "O|z!ll" ,
4153
+ & imgind , gd_image_ce , & to_zval , & quality , & basefilter
4154
+ ) == FAILURE ) {
4155
+ RETURN_THROWS ();
4156
+ }
4157
+ break ;
4158
+ case PHP_GDIMG_TYPE_GIF :
4159
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "O|z!" , & imgind , gd_image_ce , & to_zval ) == FAILURE ) {
4148
4160
RETURN_THROWS ();
4149
4161
}
4150
4162
break ;
4151
4163
default :
4152
- /* PHP_GDIMG_TYPE_GIF
4153
- * PHP_GDIMG_TYPE_PNG
4164
+ /*
4154
4165
* PHP_GDIMG_TYPE_JPG
4155
4166
* PHP_GDIMG_TYPE_WBM
4156
4167
* PHP_GDIMG_TYPE_WEBP
4157
- * */
4158
- if (zend_parse_parameters (argc , "O|z!ll" , & imgind , gd_image_ce , & to_zval , & quality , & basefilter ) == FAILURE ) {
4168
+ */
4169
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "O|z!l" ,
4170
+ & imgind , gd_image_ce , & to_zval , & quality
4171
+ ) == FAILURE ) {
4159
4172
RETURN_THROWS ();
4160
4173
}
4161
4174
}
4162
4175
4163
4176
im = php_gd_libgdimageptr_from_zval_p (imgind );
4164
4177
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 ) {
4168
- f = basefilter ;
4169
- }
4170
- }
4171
-
4172
- if (argc > 1 && to_zval != NULL ) {
4178
+ if (to_zval != NULL ) {
4173
4179
if (Z_TYPE_P (to_zval ) == IS_RESOURCE ) {
4174
4180
php_stream_from_zval_no_verify (stream , to_zval );
4175
4181
if (stream == NULL ) {
@@ -4190,7 +4196,7 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
4190
4196
php_error_docref (NULL , E_WARNING , "Invalid 2nd parameter, it must a filename or a stream" );
4191
4197
RETURN_FALSE ;
4192
4198
}
4193
- } else if (argc > 1 && file != NULL ) {
4199
+ } else if (file != NULL ) {
4194
4200
stream = php_stream_open_wrapper (file , "wb" , REPORT_ERRORS |IGNORE_PATH |IGNORE_URL_WIN , NULL );
4195
4201
if (stream == NULL ) {
4196
4202
RETURN_FALSE ;
@@ -4216,29 +4222,29 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
4216
4222
4217
4223
switch (image_type ) {
4218
4224
case PHP_GDIMG_TYPE_JPG :
4219
- (* func_p )(im , ctx , q );
4225
+ (* func_p )(im , ctx , quality );
4220
4226
break ;
4221
4227
case PHP_GDIMG_TYPE_WEBP :
4222
- if (q == -1 ) {
4223
- q = 80 ;
4228
+ if (quality == -1 ) {
4229
+ quality = 80 ;
4224
4230
}
4225
- (* func_p )(im , ctx , q );
4231
+ (* func_p )(im , ctx , quality );
4226
4232
break ;
4227
4233
case PHP_GDIMG_TYPE_PNG :
4228
- (* func_p )(im , ctx , q , f );
4234
+ (* func_p )(im , ctx , quality , basefilter );
4229
4235
break ;
4230
4236
case PHP_GDIMG_TYPE_XBM :
4231
4237
case PHP_GDIMG_TYPE_WBM :
4232
- if (argc < 3 ) {
4238
+ if (quality == -1 ) {
4233
4239
for (i = 0 ; i < gdImageColorsTotal (im ); i ++ ) {
4234
4240
if (!gdImageRed (im , i ) && !gdImageGreen (im , i ) && !gdImageBlue (im , i )) break ;
4235
4241
}
4236
- q = i ;
4242
+ quality = i ;
4237
4243
}
4238
4244
if (image_type == PHP_GDIMG_TYPE_XBM ) {
4239
- (* func_p )(im , file ? file : "" , q , ctx );
4245
+ (* func_p )(im , file ? file : "" , quality , ctx );
4240
4246
} else {
4241
- (* func_p )(im , q , ctx );
4247
+ (* func_p )(im , quality , ctx );
4242
4248
}
4243
4249
break ;
4244
4250
case PHP_GDIMG_TYPE_BMP :
0 commit comments