bmp-js is a pure JavaScript library for Node.js designed to encode and decode BMP image files. Currently at version 0.1.0, it supports decoding a wide range of BMP formats including 1-bit, 4-bit, 8-bit, 16-bit (555 and 565), 24-bit, and 32-bit images. Encoding, however, is limited to 24-bit BMPs without compression. Given its last recorded release was 0.1.0, the package appears to be in an unmaintained or abandoned state, lacking modern feature updates or active bug fixes. Its key differentiator is being a standalone, pure JavaScript solution without native dependencies, making it easy to integrate into Node.js projects requiring basic BMP manipulation. The project has not seen significant updates or major version releases, suggesting a stable but feature-limited and potentially outdated tool for image processing tasks.
npm install bmp-jsVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to read a BMP file, decode it using `bmp-js`, access and modify its raw pixel data (ABGR format), and then re-encode the modified data back into a new 24-bit BMP file.
Evaluate alternatives like `sharp` (which uses native bindings but is actively maintained) or other image processing libraries if active maintenance and modern features are critical.
Ensure your project is configured for CommonJS or use dynamic `import()` for ESM environments: `const bmp = await import('bmp-js');` (though still accessing methods via `bmp.default.decode`). The recommended fix for Node.js is to use `const bmp = require('bmp-js');`.If you need to encode BMPs with different bit depths or compression, consider using a more feature-rich image processing library.
When manipulating `bmpData.data`, always account for the ABGR byte order: `data[i]` (Alpha), `data[i+1]` (Blue), `data[i+2]` (Green), `data[i+3]` (Red) for pixel `i/4`.
Use the correct CommonJS require syntax to import the module: `const bmp = require('bmp-js');` and then access methods as `bmp.decode(buffer);`.Verify the file path is correct and the file exists. Use an absolute path if necessary, or ensure the file is in the current working directory of your script.
Ensure the object passed to `bmp.encode()` contains `data` (a Buffer), `width` (a Number), and `height` (a Number) with valid values, e.g., `bmp.encode({ data: pixelBuffer, width: 100, height: 50 });`.No dependency data recorded yet.