]> granicus.if.org Git - php/commitdiff
Resolve imagecropauto() default $mode quirk
authorChristoph M. Becker <cmbecker69@gmx.de>
Wed, 12 Dec 2018 16:25:37 +0000 (17:25 +0100)
committerChristoph M. Becker <cmbecker69@gmx.de>
Wed, 12 Dec 2018 16:25:37 +0000 (17:25 +0100)
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.

NEWS
UPGRADING
ext/gd/gd.c

diff --git a/NEWS b/NEWS
index d520d4658c674ffaa90657f020ce3c0bd7024709..703533274d5efc26bb6b481e0d5b4d9eb699fade 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -19,6 +19,8 @@ PHP                                                                        NEWS
     pkg-config). (Eli Schwartz)
   . The bundled libgd behaves now like system libgd wrt. IMG_CROP_DEFAULT never
     falling back to IMG_CROP_SIDES.
+  . The default $mode parameter of imagecropauto() has been changed to
+    IMG_CROP_DEFAULT; passing -1 is now deprecated.
 
 - Hash:
   . The hash extension is now an integral part of PHP and cannot be disabled
index a012204dea38d24a5b3ed924c87fadb5326f34fb..1734b7298ff1d64e54325e585424358583cc646d 100644 (file)
--- a/UPGRADING
+++ b/UPGRADING
@@ -120,6 +120,8 @@ PHP 7.4 UPGRADE NOTES
     that of system libgd:
      * IMG_CROP_DEFAULT is no longer falling back to IMG_CROP_SIDES
      * Threshold-cropping now uses the algorithm of system libgd
+  . The default $mode parameter of imagecropauto() has been changed to
+    IMG_CROP_DEFAULT; passing -1 is now deprecated.
 
 - Hash:
   . The hash extension cannot be disabled anymore and is always an integral
index 66464960c7bb143008877d0a9ace764995fb7575..f4b7d2c2a5bd164a7db6065926096de25fa9cec4 100644 (file)
@@ -4685,12 +4685,12 @@ PHP_FUNCTION(imagecrop)
 }
 /* }}} */
 
-/* {{{ proto resource imagecropauto(resource im [, int mode [, float threshold [, int color]]])
+/* {{{ proto resource imagecropauto(resource im [, int mode = GD_CROP_DEFAULT [, float threshold [, int color]]])
    Crop an image automatically using one of the available modes. */
 PHP_FUNCTION(imagecropauto)
 {
        zval *IM;
-       zend_long mode = -1;
+       zend_long mode = GD_CROP_DEFAULT;
        zend_long color = -1;
        double threshold = 0.5f;
        gdImagePtr im;
@@ -4706,7 +4706,9 @@ PHP_FUNCTION(imagecropauto)
 
        switch (mode) {
                case -1:
+                       php_error_docref(NULL, E_DEPRECATED, "Crop mode -1 is deprecated. Use IMG_CROP_DEFAULT instead.");
                        mode = GD_CROP_DEFAULT;
+                       /* FALLTHRU */
                case GD_CROP_DEFAULT:
                case GD_CROP_TRANSPARENT:
                case GD_CROP_BLACK: