php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77198 auto cropping has insufficient precision
Submitted: 2018-11-25 13:45 UTC Modified: 2018-11-25 13:45 UTC
From: cmb@php.net Assigned: cmb (profile)
Status: Closed Package: GD related
PHP Version: 7.2.12 OS: *
Private report: No CVE-ID: None
 [2018-11-25 13:45 UTC] cmb@php.net
Description:
------------
Forwarding from upstream[1] since PHP's bundled libgd is affected
as well.

Consider, for instance, an 8x8 pixel image with a white background
with a single black pixel anywhere (except for the corners).
Applying gdImageCropAuto(…, GD_CROP_SIDES) is supposed to yield a
1x1 pixel image with a black pixel. The test script is exercising
this for all 60 possible black pixel positions.

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

Test script:
---------------
<?php

function createWhiteImageWithBlackPixelAt($x, $y)
{
    $im = imagecreatetruecolor(8, 8);
    imagefilledrectangle($im, 0, 0, 7, 7, 0xffffff);
    imagesetpixel($im, $x, $y, 0x000000);
    return $im;
}

$count = 0;
for ($y = 0; $y < 8; $y++) {
    for ($x = 0; $x < 8; $x++) {
        if (($x == 0 && ($y == 0 || $y == 7)) || ($x == 7 && ($y == 0 || $y == 7))) {
            continue; // skip the corners
        }
        $orig = createWhiteImageWithBlackPixelAt($x, $y);
        $cropped = imagecropauto($orig, IMG_CROP_SIDES);
        if ($cropped) {
            if (imagesx($cropped) === 1 && imagesy($cropped) === 1 && imagecolorat($cropped, 0, 0) === 0x000000) {
                $count++;
            }
            imagedestroy($cropped);
        }
        imagedestroy($orig);
    }
}

echo "$count\n";

Expected result:
----------------
60

Actual result:
--------------
0

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-11-25 13:45 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2018-11-25 15:00 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=b47b8886dd17d080c74c401f7893ba9f4ccb83d3
Log: Fix #77198: auto cropping has insufficient precision
 [2018-11-25 15:00 UTC] cmb@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC