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: cmb@php.net 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] cmb@php.net
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] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2018-11-25 18:05 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
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] cmb@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 15 08:01:30 2024 UTC