@@ -891,6 +891,11 @@ ZEND_BEGIN_ARG_INFO(arginfo_imageflip, 0)
891
891
ZEND_ARG_INFO (0 , mode )
892
892
ZEND_END_ARG_INFO ()
893
893
894
+ ZEND_BEGIN_ARG_INFO (arginfo_imagecrop , 0 )
895
+ ZEND_ARG_INFO (0 , im )
896
+ ZEND_ARG_INFO (0 , rect )
897
+ ZEND_END_ARG_INFO ()
898
+
894
899
ZEND_BEGIN_ARG_INFO (arginfo_imagecropauto , 0 )
895
900
ZEND_ARG_INFO (0 , im )
896
901
ZEND_ARG_INFO (0 , mode )
@@ -957,6 +962,7 @@ const zend_function_entry gd_functions[] = {
957
962
#ifdef HAVE_GD_BUNDLED
958
963
PHP_FE (imageantialias , arginfo_imageantialias )
959
964
PHP_FE (imageflip , arginfo_imageflip )
965
+ PHP_FE (imagecrop , arginfo_imagecrop )
960
966
PHP_FE (imagecropauto , arginfo_imagecropauto )
961
967
#endif
962
968
@@ -1218,7 +1224,10 @@ PHP_MINIT_FUNCTION(gd)
1218
1224
REGISTER_LONG_CONSTANT ("IMG_CROP_BLACK" , GD_CROP_BLACK , CONST_CS | CONST_PERSISTENT );
1219
1225
REGISTER_LONG_CONSTANT ("IMG_CROP_WHITE" , GD_CROP_WHITE , CONST_CS | CONST_PERSISTENT );
1220
1226
REGISTER_LONG_CONSTANT ("IMG_CROP_SIDES" , GD_CROP_SIDES , CONST_CS | CONST_PERSISTENT );
1227
+ #ifdef GD_ENABLE_CROP_THRESHOLD
1221
1228
REGISTER_LONG_CONSTANT ("IMG_CROP_THRESHOLD" , GD_CROP_THRESHOLD , CONST_CS | CONST_PERSISTENT );
1229
+ #endif
1230
+
1222
1231
#else
1223
1232
REGISTER_LONG_CONSTANT ("GD_BUNDLED" , 0 , CONST_CS | CONST_PERSISTENT );
1224
1233
#endif
@@ -5141,9 +5150,69 @@ PHP_FUNCTION(imageflip)
5141
5150
}
5142
5151
/* }}} */
5143
5152
5153
+ /* {{{ proto void imagecrop(resource im, array rect)
5154
+ Crop an image using the given coordinates and size, x, y, width and height. */
5155
+ PHP_FUNCTION (imagecrop )
5156
+ {
5157
+ zval * IM ;
5158
+ long mode = -1 ;
5159
+ long color = -1 ;
5160
+ double threshold = 0.5f ;
5161
+ gdImagePtr im ;
5162
+ gdImagePtr im_crop ;
5163
+ HashTable rect_hash ;
5164
+ gdRect rect ;
5165
+ zval * * tmp ;
5144
5166
5145
- /* {{{ proto void imageflip(resource im, int mode)
5146
- Flip an image (in place) horizontally, vertically or both directions. */
5167
+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "r|h" , & IM , & rect_hash ) == FAILURE ) {
5168
+ return ;
5169
+ }
5170
+
5171
+ ZEND_FETCH_RESOURCE (im , gdImagePtr , & IM , -1 , "Image" , le_gd );
5172
+
5173
+ if (zend_hash_find (& rect_hash , "x" , strlen ("x" ), (void * * )& tmp ) != FAILURE ) {
5174
+ rect .x = Z_LVAL_PP (tmp );
5175
+ } else {
5176
+ php_error_docref (NULL TSRMLS_CC , E_WARNING , "Missing x position ");
5177
+ RETURN_FALSE ;
5178
+ }
5179
+
5180
+ if (zend_hash_find (& rect_hash , "y" , strlen ("x" ), (void * * )& tmp ) != FAILURE ) {
5181
+ rect .y = Z_LVAL_PP (tmp );
5182
+ } else {
5183
+ php_error_docref (NULL TSRMLS_CC , E_WARNING , "Missing y position ");
5184
+ RETURN_FALSE ;
5185
+ }
5186
+
5187
+ if (zend_hash_find (& rect_hash , "width" , strlen ("x" ), (void * * )& tmp ) != FAILURE ) {
5188
+ rect .width = Z_LVAL_PP (tmp );
5189
+ } else {
5190
+ php_error_docref (NULL TSRMLS_CC , E_WARNING , "Missing width ");
5191
+ RETURN_FALSE ;
5192
+ }
5193
+
5194
+ if (zend_hash_find (& rect_hash , "height" , strlen ("x" ), (void * * )& tmp ) != FAILURE ) {
5195
+ rect .width = Z_LVAL_PP (tmp );
5196
+ } else {
5197
+ php_error_docref (NULL TSRMLS_CC , E_WARNING , "Missing height ");
5198
+ RETURN_FALSE ;
5199
+ }
5200
+
5201
+ im_crop = gdImageCrop (im , & rect );
5202
+
5203
+ php_error_docref (NULL TSRMLS_CC , E_WARNING , "Unknown flip mode ");
5204
+ RETURN_FALSE ;
5205
+
5206
+ if (im_crop == NULL ) {
5207
+ RETURN_FALSE ;
5208
+ } else {
5209
+ ZEND_REGISTER_RESOURCE (return_value , im_crop , le_gd );
5210
+ }
5211
+ }
5212
+ /* }}} */
5213
+
5214
+ /* {{{ proto void imagecropauto(resource im [, int mode [, threshold [, color]]])
5215
+ Crop an image automatically using one of the available modes. */
5147
5216
PHP_FUNCTION (imagecropauto )
5148
5217
{
5149
5218
zval * IM ;
@@ -5169,15 +5238,15 @@ PHP_FUNCTION(imagecropauto)
5169
5238
case GD_CROP_SIDES :
5170
5239
im_crop = gdImageCropAuto (im , mode );
5171
5240
break ;
5172
-
5241
+ #ifdef GD_ENABLE_CROP_THRESHOLD
5173
5242
case GD_CROP_THRESHOLD :
5174
5243
if (color < 0 ) {
5175
5244
php_error_docref (NULL TSRMLS_CC , E_WARNING , "Color argument missing with threshold mode" );
5176
5245
RETURN_FALSE ;
5177
5246
}
5178
5247
im_crop = gdImageCropThreshold (im , color , (float ) threshold );
5179
5248
break ;
5180
-
5249
+ #endif
5181
5250
default :
5182
5251
php_error_docref (NULL TSRMLS_CC , E_WARNING , "Unknown flip mode ");
5183
5252
RETURN_FALSE ;
0 commit comments