Bug #73291 [Opn->Csd]: imagecropauto() $threshold differs from external libgd
| From: | cmb@php.net | Date: | Sat, 01 Dec 2018 17:49:45 +0000 |
| Subject: | Bug #73291 [Opn->Csd]: imagecropauto() $threshold differs from external libgd | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-218240@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73291&edit=1
ID: 73291
Updated by: cmb@php.net
Reported by: cmb@php.net
Summary: imagecropauto() $threshold differs from external
libgd
-Status: Open
+Status: Closed
Type: Bug
Package: GD related
Operating System: *
PHP Version: 7.0.11
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=dcad13e8c936646ae9cfd4a4ef97a7443a23e774
Log: Fix #73291: imagecropauto() $threshold differs from external libgd
Previous Comments:
------------------------------------------------------------------------
[2016-10-11 15:07:34] cmb@php.net
FTR: I've filed a suggestion to improve the algorithm, see
<https://github.com/libgd/libgd/issues/334>.
------------------------------------------------------------------------
[2016-10-11 14:53:04] cmb@php.net
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 this bug report at https://bugs.php.net/bug.php?id=73291&edit=1