ZEND_ARG_INFO(0, mode)
ZEND_END_ARG_INFO()
+ZEND_BEGIN_ARG_INFO(arginfo_imagecrop, 0)
+ ZEND_ARG_INFO(0, im)
+ ZEND_ARG_INFO(0, rect)
+ZEND_END_ARG_INFO()
+
ZEND_BEGIN_ARG_INFO(arginfo_imagecropauto, 0)
ZEND_ARG_INFO(0, im)
ZEND_ARG_INFO(0, mode)
#ifdef HAVE_GD_BUNDLED
PHP_FE(imageantialias, arginfo_imageantialias)
PHP_FE(imageflip, arginfo_imageflip)
+ PHP_FE(imagecrop, arginfo_imagecrop)
PHP_FE(imagecropauto, arginfo_imagecropauto)
#endif
REGISTER_LONG_CONSTANT("IMG_CROP_BLACK", GD_CROP_BLACK, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("IMG_CROP_WHITE", GD_CROP_WHITE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("IMG_CROP_SIDES", GD_CROP_SIDES, CONST_CS | CONST_PERSISTENT);
+#ifdef GD_ENABLE_CROP_THRESHOLD
REGISTER_LONG_CONSTANT("IMG_CROP_THRESHOLD", GD_CROP_THRESHOLD, CONST_CS | CONST_PERSISTENT);
+#endif
+
#else
REGISTER_LONG_CONSTANT("GD_BUNDLED", 0, CONST_CS | CONST_PERSISTENT);
#endif
}
/* }}} */
+/* {{{ proto void imagecrop(resource im, array rect)
+ Crop an image using the given coordinates and size, x, y, width and height. */
+PHP_FUNCTION(imagecrop)
+{
+ zval *IM;
+ long mode = -1;
+ long color = -1;
+ double threshold = 0.5f;
+ gdImagePtr im;
+ gdImagePtr im_crop;
+ HashTable rect_hash;
+ gdRect rect;
+ zval **tmp;
-/* {{{ proto void imageflip(resource im, int mode)
- Flip an image (in place) horizontally, vertically or both directions. */
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|h", &IM, &rect_hash) == FAILURE) {
+ return;
+ }
+
+ ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
+
+ if (zend_hash_find(&rect_hash, "x", strlen("x"), (void **)&tmp) != FAILURE) {
+ rect.x = Z_LVAL_PP(tmp);
+ } else {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Missing x position");
+ RETURN_FALSE;
+ }
+
+ if (zend_hash_find(&rect_hash, "y", strlen("x"), (void **)&tmp) != FAILURE) {
+ rect.y = Z_LVAL_PP(tmp);
+ } else {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Missing y position");
+ RETURN_FALSE;
+ }
+
+ if (zend_hash_find(&rect_hash, "width", strlen("x"), (void **)&tmp) != FAILURE) {
+ rect.width = Z_LVAL_PP(tmp);
+ } else {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Missing width");
+ RETURN_FALSE;
+ }
+
+ if (zend_hash_find(&rect_hash, "height", strlen("x"), (void **)&tmp) != FAILURE) {
+ rect.width = Z_LVAL_PP(tmp);
+ } else {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Missing height");
+ RETURN_FALSE;
+ }
+
+ im_crop = gdImageCrop(im, &rect);
+
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown flip mode");
+ RETURN_FALSE;
+
+ if (im_crop == NULL) {
+ RETURN_FALSE;
+ } else {
+ ZEND_REGISTER_RESOURCE(return_value, im_crop, le_gd);
+ }
+}
+/* }}} */
+
+/* {{{ proto void imagecropauto(resource im [, int mode [, threshold [, color]]])
+ Crop an image automatically using one of the available modes. */
PHP_FUNCTION(imagecropauto)
{
zval *IM;
case GD_CROP_SIDES:
im_crop = gdImageCropAuto(im, mode);
break;
-
+#ifdef GD_ENABLE_CROP_THRESHOLD
case GD_CROP_THRESHOLD:
if (color < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Color argument missing with threshold mode");
}
im_crop = gdImageCropThreshold(im, color, (float) threshold);
break;
-
+#endif
default:
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown flip mode");
RETURN_FALSE;