Bug #73317 [NEW]: image2wbmp() interprets $threshold as $fg
| From: | cmb@php.net | Date: | Thu, 13 Oct 2016 16:38:50 +0000 |
| Subject: | Bug #73317 [NEW]: image2wbmp() interprets $threshold as $fg | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-204674@lists.php.net to get a copy of this message | ||
From: cmb
Operating system: *
PHP version: 5.6.26
Package: GD related
Bug Type: Bug
Bug description:image2wbmp() interprets $threshold as $fg
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 bug report at https://bugs.php.net/bug.php?id=73317&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=73317&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=73317&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=73317&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=73317&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=73317&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=73317&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=73317&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=73317&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=73317&r=support
Expected behavior: https://bugs.php.net/fix.php?id=73317&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=73317&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=73317&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=73317&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73317&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=73317&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=73317&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=73317&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=73317&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=73317&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=73317&r=mysqlcfg