Bug #79622 [Nab]: Imagewbmp outputs an white image with something incomprehensible.

From: Date: Sat, 23 May 2020 09:29:17 +0000
Subject: Bug #79622 [Nab]: Imagewbmp outputs an white image with something incomprehensible.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-227138@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79622&edit=1 ID: 79622 Updated by: cmb@php.net Reported by: cretu dot andrei at zoho dot com Summary: Imagewbmp outputs an white image with something incomprehensible. Status: Not a bug Type: Bug Package: *Graphics related Operating System: Windows 7, X64 PHP Version: Irrelevant Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2020-05-23 06:29:06] 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 06:21:12] 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:12:33] 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 05:49:45] requinix@php.net WBMPs only do black and white. ------------------------------------------------------------------------ [2020-05-23 03:43:03] 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... ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=79622&edit=1

« previous php.bugs (#227138) next »