|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79622 Imagewbmp outputs an white image with something incomprehensible.
Submitted: 2020-05-23 03:43 UTC Modified: 2020-05-23 09:29 UTC
From: cretu dot andrei at zoho dot com Assigned:
Status: Not a bug Package: *Graphics related
PHP Version: Irrelevant OS: Windows 7, X64
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: cretu dot andrei at zoho dot com
New email:
PHP Version: OS:


 [2020-05-23 03:43 UTC] cretu dot andrei at zoho dot com
I'm using imagecreatefromjpeg to create an image from a source. Then I'm using imagewbmp to save it as .wbmp.

The image saved is 98% white with a small portion black.

Test script:
$image_object = imagecreatefromjpeg('');

imagewbmp($image_object, 'new_image.wbmp');

Expected result:
A black and white image.

Actual result:
I see an image allmost white...


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-05-23 05:49 UTC]
-Status: Open +Status: Not a bug
 [2020-05-23 05:49 UTC]
WBMPs only do black and white.
 [2020-05-23 06:12 UTC] cretu dot andrei at zoho dot com
Have you tested the code ?

Here is the original image:
Here is the result:

Is that ok ?
 [2020-05-23 06:21 UTC]
WBMPs. Are. Only. Black. And. White.

Most of your source image is light colored. It will be translated into white. The small portions that are dark will be translated into black.
 [2020-05-23 06:29 UTC]
If I load your source image into GIMP and have it convert the image to monochrome, which it does so in a smart way using dithering that GD cannot do, then save and convert with PHP, I get
 [2020-05-23 09:29 UTC]
imagewbmp() only considers pixels with exactly $foreground color
to be foreground; all other color values are considered
background.  So just feeding in an arbitrary JPEG is not supposed
to work.  Instead, convert the JPEG to a palette image with only 2
colors, and then set $foreground to be either color no. 0 or 1.

$im = imagecreatefromjpeg(__DIR__ . '/79622.jpg');
imagetruecolortopalette($im, true, 2);
imagewbmp($im, __DIR__ . '/79622.wbmp', 0);

The script above uses dithering with a result roughly similar to
what @requinix posted above.  Dithering is not strictly necessary,
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 16 13:01:29 2024 UTC