php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #53175 Confusing (ambiguous) imagecolorallocate return value when color is black
Submitted: 2010-10-26 22:50 UTC Modified: 2010-11-07 05:18 UTC
From: orlin dot hristov at gmail dot com Assigned: kalle (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.2.14 OS: Windows 7/2003 Server
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: orlin dot hristov at gmail dot com
New email:
PHP Version: OS:

 

 [2010-10-26 22:50 UTC] orlin dot hristov at gmail dot com
Description:
------------
According to the online documentation the imagecolorallocate function returns "A color identifier or FALSE if the allocation failed".

The confusion comes when I try to allocate black color, passing 0x0 to all the three color components. The function always returns 0, which means FALSE, but it looks like the identifier is valid. Future use of it in other gd functions leads to successful results.

I also noticed in the online documentation that in prior to 5.1.3 versions of PHP this function returns -1 if the allocation failed, so it is eather a problem in the documentation or bug in the gd extension I am using.

Test script:
---------------
Code:
header("Content-type: image/png");
$im = imagecreatetruecolor(300, 100);
$font_color = imagecolorallocate($im, 0, 0, 0); // Black
$bg_color = imagecolorallocate($im, 255, 255, 0); // Yellow
imagefill($im, 0, 0, $bg_color);
imagestring($im, 10, 40, 40, "font color identifier is: $font_color", $font_color);
imagepng($im);
imagedestroy($im);

Output:
Yellow image with black colored string: "font color identifier is: 0"

Expected result:
----------------
The imagecolorallocate function should not return zero value for valid color identifiers or the documentation should be changed.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-10-26 23:09 UTC] kalle@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: kalle
 [2010-11-07 05:18 UTC] kalle@php.net
Automatic comment from SVN on behalf of kalle
Revision: http://svn.php.net/viewvc/?view=revision&revision=305144
Log: Fixed bug #53175 (Confusing (ambiguous) imagecolorallocate return value when color is black)
 [2010-11-07 05:18 UTC] kalle@php.net
-Status: Assigned +Status: Closed
 [2010-11-07 05:18 UTC] kalle@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 [2020-02-07 06:08 UTC] phpdocbot@php.net
Automatic comment on behalf of kalle
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=ead13ffe21cc01ebff52a847495a26eb698ac940
Log: Fixed bug #53175 (Confusing (ambiguous) imagecolorallocate return value when color is black)
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 07:00:01 2026 UTC