php.net |  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
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: cmb@php.net Assigned: cmb (profile)
Status: Closed Package: GD related
PHP Version: 5.6.26 OS: *
Private report: No CVE-ID: None
 [2016-10-13 16:38 UTC] cmb@php.net
Description:
------------
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
imagefilter() with IMG_FILTER_CONTRAST and IMG_FILTER_GRAYSCALE
might deliver this functionality, though. And of course, one could
output the image as PNG and use png2wbmp().

[1] <http://git.php.net/?p=php-src.git;a=commit;h=cb5c9156c233a260e7a588141863720de82d2926>

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

$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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-10-06 14:30 UTC] cmb@php.net
-Status: Open +Status: Closed -Type: Bug +Type: Documentation Problem -Assigned To: +Assigned To: cmb
 [2018-10-06 14:30 UTC] cmb@php.net
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] <https://wiki.php.net/rfc/image2wbmp>
[2] <http://svn.php.net/viewvc?view=revision&revision=345112>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 08:01:28 2024 UTC