# What to do with image2wbmp()?

- Thread: https://externals.io/message/102025
- Original archive: https://news-web.php.net/php.internals/102025
- Started by Christoph M. Becker on 2018-04-05T12:04:03+00:00
- Messages: 3
- RFC: Deprecate and Remove image2wbmp() (Implemented (PHP 7.3)) — https://externals.io/rfc/image2wbmp.md
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #102025 — Christoph M. Becker — 2018-04-05T12:04:03+00:00

URL: https://externals.io/message/102025#102025

Hi everybody!

<https://bugs.php.net/73317> is still unresolved, and I'm not sure how
to resolve it.

TL;DR: the $threshold parameter of image2wbmp() is supposed to specify a
*brightness threshold* for the required black and white conversion of
the image.  However, as of PHP 5.0.0 it is actually interpreted as the
*foreground color*; all other colors are treated as background.  This
makes image2wbmp() basically identical to imagewbmp().

Any suggestions on how to proceed here?

-- 
Christoph M. Becker

---

## #102034 — Kalle Sommer Nielsen — 2018-04-13T04:58:23+00:00

URL: https://externals.io/message/102025#102034 · In reply to: #102025

Hi

2018-04-05 14:04 GMT+02:00 Christoph M. Becker <cmbecker69@gmx.de>:
> Hi everybody!
>
> <https://bugs.php.net/73317> is still unresolved, and I'm not sure how
> to resolve it.
>
> TL;DR: the $threshold parameter of image2wbmp() is supposed to specify a
> *brightness threshold* for the required black and white conversion of
> the image.  However, as of PHP 5.0.0 it is actually interpreted as the
> *foreground color*; all other colors are treated as background.  This
> makes image2wbmp() basically identical to imagewbmp().
>
> Any suggestions on how to proceed here?

If thats the case that its basically identical, then a PHP_DEP_FE
should be sufficient for image2wbmp() and a removal in future version,
given its a rarely used function and migration is easy, even 7.4 could
potentially be fine for removal.



-- 
regards,

Kalle Sommer Nielsen
kalle@php.net

---

## #102063 — Christoph M. Becker — 2018-04-19T23:09:51+00:00

URL: https://externals.io/message/102025#102063 · In reply to: #102034

> 2018-04-05 14:04 GMT+02:00 Christoph M. Becker <cmbecker69@gmx.de>:
>
> > […]
> 
> If thats the case that its basically identical, then a PHP_DEP_FE
> should be sufficient for image2wbmp() and a removal in future version,
> given its a rarely used function and migration is easy, even 7.4 could
> potentially be fine for removal.

Thanks, Kalle!

To clarify the behavioral problem: image2wbmp() is supposed to use
_php_image_bw_convert() to do the conversion.  However, that does not
happen anymore since the commit[1] I've mentioned in the bug report.
The problem is that the fallthrough to case PHP_GDIMG_TYPE_JPEG[2] had
been intended (but not documented!), so that _php_image_bw_convert()
(which is stored in func_p) would have been called, but now
gdImageWBMP()[3] is called directly without converting to a black and
white image according to the given threshold.

It is quite interesting that it took apparently more than *ten* years
until the bug has been reported[4].  This might be due to nobody using
WBMP (see <https://bugs.php.net/76179>, though).

Anyhow, I have to agree to the deprecation/removal suggestion, since:

  * fixing *this* 10y old bug is likely to cause more harm than good
  * a B/W conversion should be a *general* feature of GD (or likely
rather libgd)
  * the B/W conversion[5] is very simplistic, and does not fit to
gdImageGrayScale()'s[6] algorithm[7]

I shall pursue the RFC process.

[1]
<http://git.php.net/?p=php-src.git;a=commit;h=cb5c9156c233a260e7a588141863720de82d2926>
[2]
<https://github.com/php/php-src/commit/cb5c9156c233a260e7a588141863720de82d2926#diff-bdf11f69d3dc3fb9601e59055a169449R1728>
[3] <http://libgd.github.io/manuals/2.2.5/files/gd_wbmp-c.html#gdImageWBMP>
[4] <https://bugs.php.net/73317>
[5] <https://github.com/php/php-src/blob/PHP-7.2.4/ext/gd/gd.c#L4140>
[6]
<http://libgd.github.io/manuals/2.2.5/files/gd_filter-c.html#gdImageGrayScale>
[7]
<https://github.com/php/php-src/blob/PHP-7.2.4/ext/gd/libgd/gd_filter.c#L74>

-- 
Christoph M. Becker
