Bug #73291 [NEW]: imagecropauto() $threshold differs from external libgd

From: Date: Tue, 11 Oct 2016 14:53:06 +0000
Subject: Bug #73291 [NEW]: imagecropauto() $threshold differs from external libgd
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-204601@lists.php.net to get a copy of this message
From: cmb Operating system: * PHP version: 7.0.11 Package: GD related Bug Type: Bug Bug description:imagecropauto() $threshold differs from external libgd Description: ------------ Depending on whether GD is built with the bundled or an external libgd, imagecropauto()'s $threshold argument is treated differently. External libgd assumes mostly much larger $threshold values to crop the same amount from the image than the bundled libgd. The different behavior stems from the different algorithms[1][2]. Actually, I think the algorithm in the bundled is slightly saner than the one in external libgd (but both appear to be somewhat arbitrary). Nonetheless the bundled libgd should be fixed to match the external libgd; otherwise portable code would have to cater to these differences. [1] <https://github.com/libgd/libgd/blob/gd-2.2.3/src/gd_color.c#L14-L16> [2] <https://github.com/php/php-src/blob/PHP-7.0.12/ext/gd/libgd/gd_crop.c#L350-L352> Test script: --------------- <?php $src = imagecreatetruecolor(255, 255); $white = imagecolorallocate($src, 255, 255, 255); imagefilledrectangle($src, 0, 0, 254, 254, $white); for ($i = 254; $i > 0; $i--) { $color = imagecolorallocate($src, $i, $i, $i); imagefilledellipse($src, 127, 127, $i, $i, $color); } foreach ([0.1, 0.5, 1.0, 10.0] as $threshold) { $dst = imagecropauto($src, IMG_CROP_THRESHOLD, $threshold, $white); if ($dst !== false) { printf("size: %d*%d\n", imagesx($dst), imagesy($dst)); } else { printf("cropped to zero size\n"); } } Expected result: ---------------- [external libgd] size: 247*247 size: 237*237 size: 229*229 size: 175*175 Actual result: -------------- [bundled libgd] size: 253*253 size: 219*219 size: 109*109 cropped to zero size -- Edit bug report at https://bugs.php.net/bug.php?id=73291&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=73291&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=73291&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=73291&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=73291&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=73291&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=73291&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=73291&r=needscript Try newer version: https://bugs.php.net/fix.php?id=73291&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=73291&r=support Expected behavior: https://bugs.php.net/fix.php?id=73291&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=73291&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=73291&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=73291&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73291&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=73291&r=dst IIS Stability: https://bugs.php.net/fix.php?id=73291&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=73291&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=73291&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=73291&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=73291&r=mysqlcfg

« previous php.bugs (#204601) next »