Skip to content

Commit 8c781c1

Browse files
committed
Resolve imagecropauto() default $mode quirk
The `$mode` parameter of `imagecropauto()` defaults to `-1`. However, `-1` is changed to `GD_CROP_DEFAULT` right away, so basically the default is `GD_CROP_DEFAULT`, which is rather confusing and unnecessary. Therefore, we change the default to `IMG_CROP_DEFAULT`, but still allow an explicit `-1` to be passed for BC reasons, in which case we trigger a deprecation notice, so we can rid the `-1` support eventually.
1 parent 40c4d7f commit 8c781c1

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ PHP NEWS
1919
pkg-config). (Eli Schwartz)
2020
. The bundled libgd behaves now like system libgd wrt. IMG_CROP_DEFAULT never
2121
falling back to IMG_CROP_SIDES.
22+
. The default $mode parameter of imagecropauto() has been changed to
23+
IMG_CROP_DEFAULT; passing -1 is now deprecated.
2224

2325
- Hash:
2426
. The hash extension is now an integral part of PHP and cannot be disabled

UPGRADING

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ PHP 7.4 UPGRADE NOTES
120120
that of system libgd:
121121
* IMG_CROP_DEFAULT is no longer falling back to IMG_CROP_SIDES
122122
* Threshold-cropping now uses the algorithm of system libgd
123+
. The default $mode parameter of imagecropauto() has been changed to
124+
IMG_CROP_DEFAULT; passing -1 is now deprecated.
123125

124126
- Hash:
125127
. The hash extension cannot be disabled anymore and is always an integral

ext/gd/gd.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4685,12 +4685,12 @@ PHP_FUNCTION(imagecrop)
46854685
}
46864686
/* }}} */
46874687

4688-
/* {{{ proto resource imagecropauto(resource im [, int mode [, float threshold [, int color]]])
4688+
/* {{{ proto resource imagecropauto(resource im [, int mode = GD_CROP_DEFAULT [, float threshold [, int color]]])
46894689
Crop an image automatically using one of the available modes. */
46904690
PHP_FUNCTION(imagecropauto)
46914691
{
46924692
zval *IM;
4693-
zend_long mode = -1;
4693+
zend_long mode = GD_CROP_DEFAULT;
46944694
zend_long color = -1;
46954695
double threshold = 0.5f;
46964696
gdImagePtr im;
@@ -4706,7 +4706,9 @@ PHP_FUNCTION(imagecropauto)
47064706

47074707
switch (mode) {
47084708
case -1:
4709+
php_error_docref(NULL, E_DEPRECATED, "Crop mode -1 is deprecated. Use IMG_CROP_DEFAULT instead.");
47094710
mode = GD_CROP_DEFAULT;
4711+
/* FALLTHRU */
47104712
case GD_CROP_DEFAULT:
47114713
case GD_CROP_TRANSPARENT:
47124714
case GD_CROP_BLACK:

0 commit comments

Comments
 (0)