php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #78370 imagefilltoborder does not fill
Submitted: 2019-08-04 12:05 UTC Modified: 2019-08-05 07:29 UTC
From: 1602352639 at qq dot com Assigned:
Status: Verified Package: GD related
PHP Version: Irrelevant OS: Windows10
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: 1602352639 at qq dot com
New email:
PHP Version: OS:

 

 [2019-08-04 12:05 UTC] 1602352639 at qq dot com
Description:
------------
---
From manual page: https://php.net/function.imagefilltoborder
---
当被填充的图形是由imagefilledellipse创建时,可能出现无法正确填充的情况

Test script:
---------------
<?php
header("content-type:image/png");
$res=imagecreate(800,400);
$bmgColor=imagecolorallocate($res,54,125,215);
$darkPen1=imagecolorallocate($res,255*0.5,69*0.5,215*0.5);
$penColor1=imagecolorallocate($res,255,69,215);

$filledTime=15;
while($filledTime--)
{
    imagefilledellipse($res,400,200+$filledTime,100,40,$darkPen1); 
}   
imagefilledellipse($res,400,200,100,40,$penColor1);   
      
//问题出现在这里,这时第三个参数为200
imagefilltoborder($res,400,200,$bmgColor,$penColor1); 

imagepng($res);
imagedestroy($res);
?>

Expected result:
----------------
<?php
header("content-type:image/png");
$res=imagecreate(800,400);
$bmgColor=imagecolorallocate($res,54,125,215);
$darkPen1=imagecolorallocate($res,255*0.5,69*0.5,215*0.5);
$penColor1=imagecolorallocate($res,255,69,215);

$filledTime=15;
while($filledTime--)
{
    imagefilledellipse($res,400,200+$filledTime,100,40,$darkPen1); 
}   
imagefilledellipse($res,400,200,100,40,$penColor1);  
       
/*当第三个参数改为202时,这才是预期的结果。但是第三个参数为200与202时不应该出现不同的结果,因为(400,200)与(400,202)它们都是在由imagefilledellipse($res,400,200,100,40,$penColor1)语句创建的区域里*/
imagefilltoborder($res,400,202,$bmgColor,$penColor1); 

imagepng($res);
imagedestroy($res);
?>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-08-05 07:29 UTC] cmb@php.net
-Summary: imagefilltoborder函数 +Summary: imagefilltoborder does not fill -Status: Open +Status: Verified -Type: Bug +Type: Documentation Problem
 [2019-08-05 07:29 UTC] cmb@php.net
Resulting images: <https://imgur.com/a/YAmj9zh>.

The algorithm doesn't explicitly remember which pixels have
already been set, but rather infers that from the color of the
pixel, so it can't distinguish between freshly set pixels and
pixels that are already there.  That means chosing any fill color
that is already used in the image may yield undesired results. In
this case a workaround is to first use an unused color, and to
imagefilltoborder() with the desired color afterwards:

    imagefilltoborder($res,400,200,$bmgColor,imagecolorallocate($res,0,0,0)); 
    imagefilltoborder($res,400,200,$bmgColor,$penColor1);

I'm changing this ticket to doc problem, since the current
behavior in this regard is not documented.

If you think the algorithm should be changed/improved, please
report that upstream (<https://github.com/libgd/libgd/issues>).
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun Nov 17 10:01:32 2019 UTC