Bug->Doc #73317 [Opn->Csd]: image2wbmp() interprets $threshold as $fg
| From: | cmb@php.net | Date: | Sat, 06 Oct 2018 14:30:02 +0000 |
| Subject: | Bug->Doc #73317 [Opn->Csd]: image2wbmp() interprets $threshold as $fg | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-16054@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73317&edit=1
ID: 73317
Updated by: cmb@php.net
Reported by: cmb@php.net
Summary: image2wbmp() interprets $threshold as $fg
-Status: Open
+Status: Closed
-Type: Bug
+Type: Documentation Problem
Package: GD related
Operating System: *
PHP Version: 5.6.26
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
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>
Previous Comments:
------------------------------------------------------------------------
[2018-04-03 11:55:46] cmb@php.net
Related To: Bug #76179
------------------------------------------------------------------------
[2016-10-13 16:38:46] 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.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=73317&edit=1