php.net |  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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
29 - 20 = ?
Subscribe to this entry?

 
 [2020-05-23 03:43 UTC] cretu dot andrei at zoho dot com
Description:
------------
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('http://i.pinimg.com/originals/5b/97/49/5b9749c4db7066138b085b28a229801f.jpg');

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

Expected result:
----------------
A black and white image.

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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-05-23 05:49 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2020-05-23 05:49 UTC] requinix@php.net
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: https://ibb.co/WyRngKD
Here is the result: https://easyupload.io/9r4ka6

Is that ok ?
 [2020-05-23 06:21 UTC] requinix@php.net
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] requinix@php.net
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
https://easyupload.io/b86xdf
 [2020-05-23 09:29 UTC] cmb@php.net
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.

<?php
$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,
though.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jun 19 17:01:33 2024 UTC