What is bmp-js?
The bmp-js npm package is a JavaScript library for encoding and decoding BMP (Bitmap) image files. It allows you to read BMP files, manipulate their data, and write BMP files. This can be useful for applications that need to handle BMP images directly, such as image processing tools, graphic editors, or any application that needs to work with BMP files.
What are bmp-js's main functionalities?
Decode BMP
This feature allows you to decode a BMP file into a JavaScript object. The object contains information about the BMP file, such as width, height, and pixel data.
const bmp = require('bmp-js');
const fs = require('fs');
const bmpBuffer = fs.readFileSync('path/to/your/image.bmp');
const bmpData = bmp.decode(bmpBuffer);
console.log(bmpData);
Encode BMP
This feature allows you to encode a JavaScript object into a BMP file. You can specify the pixel data, width, and height of the image, and then write the encoded BMP data to a file.
const bmp = require('bmp-js');
const fs = require('fs');
const bmpData = {
data: Buffer.from([/* pixel data */]),
width: 100,
height: 100
};
const rawData = bmp.encode(bmpData);
fs.writeFileSync('path/to/your/output.bmp', rawData.data);
Other packages similar to bmp-js
jimp
Jimp is a JavaScript Image Manipulation Program that supports various image formats, including BMP, PNG, JPEG, and GIF. It provides a wide range of image processing functionalities such as resizing, cropping, and color manipulation. Compared to bmp-js, Jimp offers more comprehensive image processing capabilities but may be more complex to use for simple BMP encoding/decoding tasks.
sharp
Sharp is a high-performance image processing library for Node.js that supports various image formats, including BMP, JPEG, PNG, WebP, and TIFF. It is known for its speed and efficiency, making it suitable for server-side image processing tasks. While sharp offers extensive image manipulation features, it is more focused on performance and may be overkill for simple BMP handling compared to bmp-js.
image-js
Image-js is a comprehensive image processing library for JavaScript that supports multiple image formats, including BMP. It provides a wide range of image manipulation functions such as filtering, transformation, and analysis. Image-js is more feature-rich compared to bmp-js, making it suitable for more complex image processing tasks.
bmp-js
A pure javascript Bmp encoder and decoder for node.js
Supports all bits decoding(1,4,8,16,24,32) and encoding with 24bit.
##Install
$ npm install bmp-js
How to use?
###Decode BMP
var bmp = require("bmp-js");
var bmpBuffer = fs.readFileSync('bit24.bmp');
var bmpData = bmp.decode(bmpBuffer);
bmpData
has all properties includes:
-
fileSize,reserved,offset
-
headerSize,width,height,planes,bitPP,compress,rawSize,hr,vr,colors,importantColors
-
palette
-
data-------byte array order by ABGR ABGR ABGR,4 bytes per pixel
###Encode RGB
var bmp = require("bmp-js");
var rawData = bmp.encode(bmpData);
License
U can use on free with MIT License