@@ -132,7 +132,6 @@ static gdImagePtr _php_image_create_from_string (zval *Data, char *tn, gdImagePt
132
132
static void _php_image_create_from (INTERNAL_FUNCTION_PARAMETERS , int image_type , char * tn , gdImagePtr (* func_p )(), gdImagePtr (* ioctx_func_p )());
133
133
static void _php_image_output (INTERNAL_FUNCTION_PARAMETERS , int image_type , char * tn , void (* func_p )());
134
134
static int _php_image_type (char data [12 ]);
135
- static void _php_image_convert (INTERNAL_FUNCTION_PARAMETERS , int image_type );
136
135
137
136
/* {{{ arginfo */
138
137
ZEND_BEGIN_ARG_INFO (arginfo_gd_info , 0 )
@@ -758,26 +757,6 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagettftext, 0)
758
757
ZEND_END_ARG_INFO ()
759
758
#endif
760
759
761
- #if defined(HAVE_GD_JPG )
762
- ZEND_BEGIN_ARG_INFO (arginfo_jpeg2wbmp , 0 )
763
- ZEND_ARG_INFO (0 , f_org )
764
- ZEND_ARG_INFO (0 , f_dest )
765
- ZEND_ARG_INFO (0 , d_height )
766
- ZEND_ARG_INFO (0 , d_width )
767
- ZEND_ARG_INFO (0 , d_threshold )
768
- ZEND_END_ARG_INFO ()
769
- #endif
770
-
771
- #if defined(HAVE_GD_PNG )
772
- ZEND_BEGIN_ARG_INFO (arginfo_png2wbmp , 0 )
773
- ZEND_ARG_INFO (0 , f_org )
774
- ZEND_ARG_INFO (0 , f_dest )
775
- ZEND_ARG_INFO (0 , d_height )
776
- ZEND_ARG_INFO (0 , d_width )
777
- ZEND_ARG_INFO (0 , d_threshold )
778
- ZEND_END_ARG_INFO ()
779
- #endif
780
-
781
760
ZEND_BEGIN_ARG_INFO_EX (arginfo_imagefilter , 0 , 0 , 2 )
782
761
ZEND_ARG_INFO (0 , im )
783
762
ZEND_ARG_INFO (0 , filtertype )
@@ -985,12 +964,6 @@ static const zend_function_entry gd_functions[] = {
985
964
986
965
PHP_FE (imagetypes , arginfo_imagetypes )
987
966
988
- #if defined(HAVE_GD_JPG )
989
- PHP_DEP_FE (jpeg2wbmp , arginfo_jpeg2wbmp )
990
- #endif
991
- #if defined(HAVE_GD_PNG )
992
- PHP_DEP_FE (png2wbmp , arginfo_png2wbmp )
993
- #endif
994
967
PHP_FE (imagelayereffect , arginfo_imagelayereffect )
995
968
PHP_FE (imagexbm , arginfo_imagexbm )
996
969
@@ -4059,216 +4032,6 @@ static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode, int
4059
4032
/* }}} */
4060
4033
#endif /* ENABLE_GD_TTF */
4061
4034
4062
- #if defined(HAVE_GD_JPG )
4063
- /* {{{ proto bool jpeg2wbmp(string f_org, string f_dest, int d_height, int d_width, int threshold)
4064
- Convert JPEG image to WBMP image */
4065
- PHP_FUNCTION (jpeg2wbmp )
4066
- {
4067
- _php_image_convert (INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_JPG );
4068
- }
4069
- /* }}} */
4070
- #endif
4071
-
4072
- #if defined(HAVE_GD_PNG )
4073
- /* {{{ proto bool png2wbmp(string f_org, string f_dest, int d_height, int d_width, int threshold)
4074
- Convert PNG image to WBMP image */
4075
- PHP_FUNCTION (png2wbmp )
4076
- {
4077
- _php_image_convert (INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_PNG );
4078
- }
4079
- /* }}} */
4080
- #endif
4081
-
4082
- /* {{{ _php_image_convert
4083
- * _php_image_convert converts jpeg/png images to wbmp and resizes them as needed */
4084
- static void _php_image_convert (INTERNAL_FUNCTION_PARAMETERS , int image_type )
4085
- {
4086
- char * f_org , * f_dest ;
4087
- size_t f_org_len , f_dest_len ;
4088
- zend_long height , width , threshold ;
4089
- gdImagePtr im_org , im_dest , im_tmp ;
4090
- char * fn_org = NULL ;
4091
- char * fn_dest = NULL ;
4092
- FILE * org , * dest ;
4093
- int dest_height = -1 ;
4094
- int dest_width = -1 ;
4095
- int org_height , org_width ;
4096
- int white , black ;
4097
- int color , color_org , median ;
4098
- int int_threshold ;
4099
- int x , y ;
4100
- float x_ratio , y_ratio ;
4101
- #ifdef HAVE_GD_JPG
4102
- zend_long ignore_warning ;
4103
- #endif
4104
-
4105
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "pplll" , & f_org , & f_org_len , & f_dest , & f_dest_len , & height , & width , & threshold ) == FAILURE ) {
4106
- return ;
4107
- }
4108
-
4109
- fn_org = f_org ;
4110
- fn_dest = f_dest ;
4111
- dest_height = height ;
4112
- dest_width = width ;
4113
- int_threshold = threshold ;
4114
-
4115
- /* Check threshold value */
4116
- if (int_threshold < 0 || int_threshold > 8 ) {
4117
- php_error_docref (NULL , E_WARNING , "Invalid threshold value '%d'" , int_threshold );
4118
- RETURN_FALSE ;
4119
- }
4120
-
4121
- /* Check origin file */
4122
- PHP_GD_CHECK_OPEN_BASEDIR (fn_org , "Invalid origin filename" );
4123
-
4124
- /* Check destination file */
4125
- PHP_GD_CHECK_OPEN_BASEDIR (fn_dest , "Invalid destination filename" );
4126
-
4127
- /* Open origin file */
4128
- org = VCWD_FOPEN (fn_org , "rb" );
4129
- if (!org ) {
4130
- php_error_docref (NULL , E_WARNING , "Unable to open '%s' for reading" , fn_org );
4131
- RETURN_FALSE ;
4132
- }
4133
-
4134
- /* Open destination file */
4135
- dest = VCWD_FOPEN (fn_dest , "wb" );
4136
- if (!dest ) {
4137
- php_error_docref (NULL , E_WARNING , "Unable to open '%s' for writing" , fn_dest );
4138
- fclose (org );
4139
- RETURN_FALSE ;
4140
- }
4141
-
4142
- switch (image_type ) {
4143
-
4144
- #ifdef HAVE_GD_JPG
4145
- case PHP_GDIMG_TYPE_JPG :
4146
- ignore_warning = INI_INT ("gd.jpeg_ignore_warning" );
4147
- im_org = gdImageCreateFromJpegEx (org , ignore_warning );
4148
- if (im_org == NULL ) {
4149
- php_error_docref (NULL , E_WARNING , "Unable to open '%s' Not a valid JPEG file" , fn_dest );
4150
- fclose (org );
4151
- fclose (dest );
4152
- RETURN_FALSE ;
4153
- }
4154
- break ;
4155
- #endif /* HAVE_GD_JPG */
4156
-
4157
- #ifdef HAVE_GD_PNG
4158
- case PHP_GDIMG_TYPE_PNG :
4159
- im_org = gdImageCreateFromPng (org );
4160
- if (im_org == NULL ) {
4161
- php_error_docref (NULL , E_WARNING , "Unable to open '%s' Not a valid PNG file" , fn_dest );
4162
- fclose (org );
4163
- fclose (dest );
4164
- RETURN_FALSE ;
4165
- }
4166
- break ;
4167
- #endif /* HAVE_GD_PNG */
4168
-
4169
- default :
4170
- php_error_docref (NULL , E_WARNING , "Format not supported" );
4171
- fclose (org );
4172
- fclose (dest );
4173
- RETURN_FALSE ;
4174
- break ;
4175
- }
4176
-
4177
- fclose (org );
4178
-
4179
- org_width = gdImageSX (im_org );
4180
- org_height = gdImageSY (im_org );
4181
-
4182
- x_ratio = (float ) org_width / (float ) dest_width ;
4183
- y_ratio = (float ) org_height / (float ) dest_height ;
4184
-
4185
- if (x_ratio > 1 && y_ratio > 1 ) {
4186
- if (y_ratio > x_ratio ) {
4187
- x_ratio = y_ratio ;
4188
- } else {
4189
- y_ratio = x_ratio ;
4190
- }
4191
- dest_width = (int ) (org_width / x_ratio );
4192
- dest_height = (int ) (org_height / y_ratio );
4193
- } else {
4194
- x_ratio = (float ) dest_width / (float ) org_width ;
4195
- y_ratio = (float ) dest_height / (float ) org_height ;
4196
-
4197
- if (y_ratio < x_ratio ) {
4198
- x_ratio = y_ratio ;
4199
- } else {
4200
- y_ratio = x_ratio ;
4201
- }
4202
- dest_width = (int ) (org_width * x_ratio );
4203
- dest_height = (int ) (org_height * y_ratio );
4204
- }
4205
-
4206
- im_tmp = gdImageCreate (dest_width , dest_height );
4207
- if (im_tmp == NULL ) {
4208
- php_error_docref (NULL , E_WARNING , "Unable to allocate temporary buffer" );
4209
- fclose (dest );
4210
- gdImageDestroy (im_org );
4211
- RETURN_FALSE ;
4212
- }
4213
-
4214
- gdImageCopyResized (im_tmp , im_org , 0 , 0 , 0 , 0 , dest_width , dest_height , org_width , org_height );
4215
-
4216
- gdImageDestroy (im_org );
4217
-
4218
- im_dest = gdImageCreate (dest_width , dest_height );
4219
- if (im_dest == NULL ) {
4220
- php_error_docref (NULL , E_WARNING , "Unable to allocate destination buffer" );
4221
- fclose (dest );
4222
- gdImageDestroy (im_tmp );
4223
- RETURN_FALSE ;
4224
- }
4225
-
4226
- white = gdImageColorAllocate (im_dest , 255 , 255 , 255 );
4227
- if (white == -1 ) {
4228
- php_error_docref (NULL , E_WARNING , "Unable to allocate the colors for the destination buffer" );
4229
- fclose (dest );
4230
- gdImageDestroy (im_tmp );
4231
- gdImageDestroy (im_dest );
4232
- RETURN_FALSE ;
4233
- }
4234
-
4235
- black = gdImageColorAllocate (im_dest , 0 , 0 , 0 );
4236
- if (black == -1 ) {
4237
- php_error_docref (NULL , E_WARNING , "Unable to allocate the colors for the destination buffer" );
4238
- fclose (dest );
4239
- gdImageDestroy (im_tmp );
4240
- gdImageDestroy (im_dest );
4241
- RETURN_FALSE ;
4242
- }
4243
-
4244
- int_threshold = int_threshold * 32 ;
4245
-
4246
- for (y = 0 ; y < dest_height ; y ++ ) {
4247
- for (x = 0 ; x < dest_width ; x ++ ) {
4248
- color_org = gdImageGetPixel (im_tmp , x , y );
4249
- median = (im_tmp -> red [color_org ] + im_tmp -> green [color_org ] + im_tmp -> blue [color_org ]) / 3 ;
4250
- if (median < int_threshold ) {
4251
- color = black ;
4252
- } else {
4253
- color = white ;
4254
- }
4255
- gdImageSetPixel (im_dest , x , y , color );
4256
- }
4257
- }
4258
-
4259
- gdImageDestroy (im_tmp );
4260
-
4261
- gdImageWBMP (im_dest , black , dest );
4262
-
4263
- fflush (dest );
4264
- fclose (dest );
4265
-
4266
- gdImageDestroy (im_dest );
4267
-
4268
- RETURN_TRUE ;
4269
- }
4270
- /* }}} */
4271
-
4272
4035
/* Section Filters */
4273
4036
#define PHP_GD_SINGLE_RES \
4274
4037
zval *SIM; \
0 commit comments