]> granicus.if.org Git - php/commitdiff
Sync behavior of gdImageAutoCrop() with upstream
authorChristoph M. Becker <cmbecker69@gmx.de>
Sun, 25 Nov 2018 15:33:14 +0000 (16:33 +0100)
committerChristoph M. Becker <cmbecker69@gmx.de>
Sat, 1 Dec 2018 14:34:10 +0000 (15:34 +0100)
Since cropping support has been added to our bundled libgd,
`gdImageAutoCrop` differs from upstream in that `GD_CROP_DEFAULT` falls
back on `GD_CROP_SIDES` if there is no transparent color in the image.
While this difference seem to be a useful improvement in our bundled
libgd, upstream has not yet signaled that there willing to back-port
it[1], so we revert it to stay in sync with upstream.

We also remove the additional NULL bailout at the end of the function,
which doesn't appear to be relevant any longer since bug 77198 has been
fixed.

[1] <https://github.com/libgd/libgd/issues/298>

NEWS
UPGRADING
ext/gd/libgd/gd_crop.c
ext/gd/tests/imagecrop_auto-ext.phpt [deleted file]
ext/gd/tests/imagecrop_auto.phpt

diff --git a/NEWS b/NEWS
index e2a92559f8e79c09adfa75031d0e3e486bf21099..e9e3795b04a180511cb08bb3d9a5a2bf0abb406f 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,8 @@ PHP                                                                        NEWS
 - GD:
   . Fixed bug #76324 (cannot detect recent versions of freetype with
     pkg-config). (Eli Schwartz)
+  . The bundled libgd behaves now like system libgd wrt. GD_CROP_DEFAULT never
+    falling back to GD_CROP_SIDES.
 
 - Hash:
   . The hash extension is now an integral part of PHP and cannot be disabled
index dc081a6b6c5c36b1d99d651225b3aae99914c2f0..3de199324dc2a0892af45ad9637773c5438ecb18 100644 (file)
--- a/UPGRADING
+++ b/UPGRADING
@@ -116,6 +116,8 @@ PHP 7.4 UPGRADE NOTES
     has been renamed to --enable-freetype and no longer accepts a directory.
     Instead pkg-config environment variables can be used to configure custom paths,
     see either ./configure --help or follow the instructions in error messages.
+  . The bundled libgd behaves now like system libgd wrt. GD_CROP_DEFAULT never
+    falling back to GD_CROP_SIDES.
 
 - Hash:
   . The hash extension cannot be disabled anymore and is always an integral
index 4221e88519457b97049a8285d9cfda0ed9899074..82ec681a47508b927ceaa04515763c9414f3fd9d 100644 (file)
@@ -109,9 +109,6 @@ gdImagePtr gdImageCropAuto(gdImagePtr im, const unsigned int mode)
                case GD_CROP_DEFAULT:
                default:
                        color = gdImageGetTransparent(im);
-                       if (color == -1) {
-                               gdGuessBackgroundColorFromCorners(im, &color);
-                       }
                        break;
        }
 
@@ -158,9 +155,6 @@ gdImagePtr gdImageCropAuto(gdImagePtr im, const unsigned int mode)
        }
        crop.width = x - crop.x + 2;
 
-       if (crop.x < 0 || crop.y < 0 || crop.width <= 0 || crop.height <= 0) {
-               return NULL;
-       }
        return gdImageCrop(im, &crop);
 }
 /*TODOs: Implement DeltaE instead, way better perceptual differences */
diff --git a/ext/gd/tests/imagecrop_auto-ext.phpt b/ext/gd/tests/imagecrop_auto-ext.phpt
deleted file mode 100644 (file)
index cc88e5d..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
---TEST--
-Testing imagecropauto()
---SKIPIF--
-<?php
-if ( ! extension_loaded('gd') || !function_exists('imagecrop')) die( 'skip GD imagecropauto not present; skipping test' );
-if (GD_BUNDLED) die('skip requires external libgd');
-?>
---FILE--
-<?php
-
-echo "TC IMG_CROP_DEFAULT\n";
-$im = imagecreatetruecolor(99, 99);
-imagefilledrectangle($im, 20, 20, 30, 30, 0xff);
-$im_crop = imagecropauto($im, IMG_CROP_DEFAULT);
-var_dump(imagesx($im_crop));
-var_dump(imagesy($im_crop));
-
-echo "Palette IMG_CROP_DEFAULT\n";
-$im = imagecreate(99, 99);
-imagefilledrectangle($im, 20, 20, 30, 30, 0xff);
-$im_crop = imagecropauto($im, IMG_CROP_DEFAULT);
-var_dump(imagesx($im_crop));
-var_dump(imagesy($im_crop));
-
-echo "TC IMG_CROP_SIDES\n";
-$im = imagecreatetruecolor(99, 99);
-imagefilledrectangle($im, 20, 20, 30, 30, 0xff);
-$im_crop = imagecropauto($im, IMG_CROP_SIDES);
-var_dump(imagesx($im_crop));
-var_dump(imagesy($im_crop));
-
-echo "Palette IMG_CROP_SIDES\n";
-$im = imagecreate(99, 99);
-imagefilledrectangle($im, 20, 20, 30, 30, 0xff);
-$im_crop = imagecropauto($im, IMG_CROP_SIDES);
-var_dump(imagesx($im_crop));
-var_dump(imagesy($im_crop));
-
-echo "TC IMG_CROP_BLACK\n";
-$im = imagecreatetruecolor(50, 50);
-imagefilledrectangle($im, 20, 20, 30, 30, 0xff);
-$im_crop = imagecropauto($im, IMG_CROP_BLACK);
-var_dump(imagesx($im_crop));
-var_dump(imagesy($im_crop));
-
-echo "Palette IMG_CROP_BLACK\n";
-$im = imagecreate(50, 50);
-$bgd = imagecolorallocate($im, 0, 0, 0);
-$b = imagecolorallocate($im, 0, 0, 255);
-imagefilledrectangle($im, 20, 20, 30, 30, 0xff);
-$im_crop = imagecropauto($im, IMG_CROP_BLACK);
-var_dump(imagesx($im_crop));
-var_dump(imagesy($im_crop));
-
-echo "IMG_CROP_THRESHOLD\n";
-$im = imagecreatefrompng(__DIR__ . "/logo_noise.png");
-$im_crop = imagecropauto($im, IMG_CROP_THRESHOLD, 0.1, 0x0);
-imagepng($im_crop, __DIR__ . "/crop_threshold.png");
-var_dump(imagesx($im_crop));
-var_dump(imagesy($im_crop));
-
-@unlink(__DIR__ . "/crop_threshold.png");
-?>
---EXPECT--
-TC IMG_CROP_DEFAULT
-int(99)
-int(99)
-Palette IMG_CROP_DEFAULT
-int(99)
-int(99)
-TC IMG_CROP_SIDES
-int(11)
-int(11)
-Palette IMG_CROP_SIDES
-int(11)
-int(11)
-TC IMG_CROP_BLACK
-int(11)
-int(11)
-Palette IMG_CROP_BLACK
-int(11)
-int(11)
-IMG_CROP_THRESHOLD
-int(240)
-int(134)
index b12cc971ee9bb3e0c43638660d2da736259fdb2f..97cac3da01deecdf498a793332c74df748a986ec 100644 (file)
@@ -3,7 +3,6 @@ Testing imagecropauto()
 --SKIPIF--
 <?php
 if ( ! extension_loaded('gd') || !function_exists('imagecrop')) die( 'skip GD imagecropauto not present; skipping test' );
-if (!GD_BUNDLED) die('skip requires bundled libgd');
 ?>
 --FILE--
 <?php
@@ -63,11 +62,11 @@ var_dump(imagesy($im_crop));
 ?>
 --EXPECT--
 TC IMG_CROP_DEFAULT
-int(11)
-int(11)
+int(99)
+int(99)
 Palette IMG_CROP_DEFAULT
-int(11)
-int(11)
+int(99)
+int(99)
 TC IMG_CROP_SIDES
 int(11)
 int(11)