php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73317 image2wbmp() interprets $threshold as $fg
Submitted: 2016-10-13 16:38 UTC Modified: -
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:
Status: Open Package: GD related
PHP Version: 5.6.26 OS: *
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Mon Jun 25 08:01:50 2018 UTC