How to use php to convert a jpg/png into a monochrome bitmap in .bmp format

I need to convert a color jpg/png map to a monochrome bitmap (not wbmp, in the GD library, but bmp), similar to the windows drawing tool:

clipboard.png

:

clipboard.png

:

clipboard.png

now we need to use php code to implement it. Do you have any ideas? Or ready-made wheels? Ask for advice!


it's too late to find information on the phone.

if you have a composer, you can try this package that specializes in dealing with images.

No, fill in the hole tomorrow.


it's too late to give a simple answer on your cell phone. If you have any questions, you'll add it tomorrow.

    For image processing on
  1. PHP, the first thing that comes to mind is GD library .
  2. is not sure whether the monochrome BMP file that appears in the title is WBMP,. If so, give priority to the jpeg2wbmp and png2wbmp functions of the GD library (or you can try first to see if the output is correct).
  3. if not, consider the traditional solution, first create the resource with fromjpeg.php" rel=" nofollow noreferrer "> imagecreatefromjpeg , then decolor it with imagefilter , and finally imagebmp output. PNG is the same process (change the function), the phone is too lazy to call.
  4. pay attention to the version requirements in GD Library introduction . BMP is quite high, and the API of the old version of GD should be on the rookie tutorial. You don't bother to search your phone, that's all.

my original idea was to convert the jpg/png picture into .bmp monochromatic bitmap, that is, only black and white, then read it pixel by pixel, and finally convert the font into a hexadecimal string. The final result is similar to the following:
E00000007F0000F8000000FF0000FE000007F700007F80001FE700001FE007FF87000007F81FFC07000
of course, the length varies depending on the size of the picture. After the latter part of the coding is completed, it is stuck in jpg/png . After repeated attempts, it is found that the picture in the format of .wbmp is also what I want, and the GD library also has the function to convert and read the format of .wbmp , so the problem is solved. But in the end, there is no way to convert it to .bmp format. .wbmp does not mean .bmp
the whole problem. I have recorded the whole problem in https://www.jianshu.com/p/779.;. Please do not hesitate to comment if there are any mistakes!


png to bmp (PHP 7 > = 7.2.0)

$png = EASYSWOOLE_ROOT . '/Uploads/Qrcode/qrcode.png'; 
$bmp = EASYSWOOLE_ROOT . '/Uploads/Qrcode/qrcode.bmp';
imagebmp($pngObj, $bmp);

imagebmp-Output a BMP image to browser or file

official documents

imagebmp- written by a netizen

Menu