1
0
mirror of https://github.com/php/php-src.git synced 2026-04-21 06:51:18 +02:00

- clean and enable threshold

This commit is contained in:
Pierre Joye
2013-02-28 19:22:06 +01:00
parent a991360344
commit 0c32a18d4c
3 changed files with 18 additions and 3 deletions

View File

@@ -894,6 +894,8 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(arginfo_imagecropauto, 0)
ZEND_ARG_INFO(0, im)
ZEND_ARG_INFO(0, mode)
ZEND_ARG_INFO(0, threshold)
ZEND_ARG_INFO(0, color)
ZEND_END_ARG_INFO()
#endif
@@ -1216,6 +1218,7 @@ PHP_MINIT_FUNCTION(gd)
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);
REGISTER_LONG_CONSTANT("IMG_CROP_THRESHOLD", GD_CROP_THRESHOLD, CONST_CS | CONST_PERSISTENT);
#else
REGISTER_LONG_CONSTANT("GD_BUNDLED", 0, CONST_CS | CONST_PERSISTENT);
#endif
@@ -5145,10 +5148,12 @@ PHP_FUNCTION(imagecropauto)
{
zval *IM;
long mode = -1;
long color = -1;
double threshold = 0.5f;
gdImagePtr im;
gdImagePtr im_crop;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &IM, &mode) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|ldl", &IM, &mode, &threshold, &color) == FAILURE) {
return;
}
@@ -5164,6 +5169,15 @@ PHP_FUNCTION(imagecropauto)
case GD_CROP_SIDES:
im_crop = gdImageCropAuto(im, mode);
break;
case GD_CROP_THRESHOLD:
if (color < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Color argument missing with threshold mode");
RETURN_FALSE;
}
im_crop = gdImageCropThreshold(im, color, (float) threshold);
break;
default:
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown flip mode");
RETURN_FALSE;

View File

@@ -733,7 +733,8 @@ enum gdCropMode {
GD_CROP_TRANSPARENT,
GD_CROP_BLACK,
GD_CROP_WHITE,
GD_CROP_SIDES
GD_CROP_SIDES,
GD_CROP_THRESHOLD
};
gdImagePtr gdImageCrop(gdImagePtr src, const gdRectPtr crop);

View File

@@ -58,7 +58,7 @@ gdImagePtr gdImageCrop(gdImagePtr src, const gdRectPtr crop)
if (src->sy < (crop->y + crop->height -1)) {
crop->height = src->sy - crop->y + 1;
}
#ifdef 0
#if 0
printf("rect->x: %i\nrect->y: %i\nrect->width: %i\nrect->height: %i\n", crop->x, crop->y, crop->width, crop->height);
#endif
if (dst == NULL) {