|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #73317 image2wbmp() interprets $threshold as $fg
Submitted: 2016-10-13 16:38 UTC Modified: 2018-10-06 14:30 UTC
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: Assigned: cmb (profile)
Status: Closed Package: GD related
PHP Version: 5.6.26 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
39 - 33 = ?
Subscribe to this entry?

 [2016-10-13 16:38 UTC]
The $threshold parameter of image2wbmp() is supposed to specify
the brightness threshold for the necessary black/white conversion.
However, as of commit cb5c9156[1], $threshold is interpreted as
the color which is used as foreground color.

As this behavioral change has been introduced with PHP 5.0.0 it
might seem best to change the documentation accordingly to avoid a
BC break. However, as it's now image2wbmp() basically behaves
identical to imagewbmp() (the latter also allows to pass a stream
as second parameter as of PHP 5.4.0), and as such makes no sense
at all.

Furthermore, there is no readily available solution for converting
an image to black and white according to a given threshold, what
appears to be required for general WBMP support. Applying
might deliver this functionality, though. And of course, one could
output the image as PNG and use png2wbmp().

[1] <;a=commit;h=cb5c9156c233a260e7a588141863720de82d2926>

Test script:

$im = imagecreate(100, 100);
imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);
$red = imagecolorallocate($im, 255, 0, 0);
$light = imagecolorallocate($im, 192, 192, 192);
$dark = imagecolorallocate($im, 64, 64, 64);
imagefilledellipse($im, 25, 25, 40, 40, $white);
imagefilledellipse($im, 75, 25, 40, 40, $red);
imagefilledellipse($im, 25, 75, 40, 40, $light);
imagefilledellipse($im, 75, 75, 40, 40, $dark);

image2wbmp($im, __DIR__ . DIRECTORY_SEPARATOR . 'image2wbmp.wbmp', $dark);

Expected result:
An image with black background and two white circles in the upper
and lower left quadrant, respectively.

Actual result:
An image with white background and a single black circle in the
lower right quadrant.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-10-06 14:30 UTC]
-Status: Open +Status: Closed -Type: Bug +Type: Documentation Problem -Assigned To: +Assigned To: cmb
 [2018-10-06 14:30 UTC]
Accoding to the “Deprecate and Remove image2wbmp()” RFC[1], it has
been decided to stick with the current behavior (and to deprecate
and later remove image2wbmp).  Therefore, this is merely a
documentation problem, which already has been resolved[2].

[1] <>
[2] <>
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sun Sep 24 15:01:24 2023 UTC