php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77200 imagecropauto(…, GD_CROP_SIDES) crops left but not right
Submitted: 2018-11-25 17:02 UTC Modified: 2018-11-25 17:03 UTC
From: [email protected] Assigned: cmb (profile)
Status: Closed Package: GD related
PHP Version: 7.2Git-2018-11-25 (Git) OS: *
Private report: No CVE-ID: None
 [2018-11-25 17:02 UTC] [email protected]
Description:
------------
Forwarding from upstream[1], since our bundled libgd is affected
as well.

The test script creates an image with four unicolored quadrants.
If the same color is used for the top left and bottom left
quadrants, imagecropauto(…, GD_CROP_SIDES) works as expected.  If
the same color is used for the top right and bottom right
quadrants, imagecropauto(…, GD_CROP_SIDES) fails to crop, though.

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

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

$orig = imagecreatetruecolor(8, 8);
$red = imagecolorallocate($orig, 255, 0, 0);
$green = imagecolorallocate($orig, 0, 255, 0);
$blue = imagecolorallocate($orig, 0, 0, 255);

imagefilledrectangle($orig, 0, 0, 3, 3, $green); // tl
imagefilledrectangle($orig, 4, 0, 7, 3, $red);   // tr
imagefilledrectangle($orig, 0, 4, 3, 7, $green); // bl
imagefilledrectangle($orig, 4, 4, 7, 7, $blue);  // br

$cropped = imagecropauto($orig, IMG_CROP_SIDES);
var_dump(imagesx($cropped));

imagefilledrectangle($orig, 0, 0, 3, 3, $red);   // tl
imagefilledrectangle($orig, 4, 0, 7, 3, $green); // tr
imagefilledrectangle($orig, 0, 4, 3, 7, $blue);  // bl
imagefilledrectangle($orig, 4, 4, 7, 7, $green); // br

$cropped = imagecropauto($orig, IMG_CROP_SIDES);
var_dump(imagesx($cropped));

Expected result:
----------------
int(4)
int(4)

Actual result:
--------------
int(4)
int(8)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-11-25 17:03 UTC] [email protected]
-Assigned To: +Assigned To: cmb
 [2018-11-25 18:05 UTC] [email protected]
Automatic comment on behalf of [email protected]
Revision: http://git.php.net/?p=php-src.git;a=commit;h=a1aaec08b5a3fc0f36cf91f034b4232285c6e793
Log: Fix #77200: imagecropauto(…, GD_CROP_SIDES) crops left but not right
 [2018-11-25 18:05 UTC] [email protected]
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jun 12 10:01:26 2025 UTC