{"id":14469,"library":"bmp-js","title":"BMP Encoder/Decoder for Node.js","description":"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.","status":"abandoned","version":"0.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/shaozilee/bmp-js","tags":["javascript","bmp","1bit","4bit","8bit","16bit","24bit","32bit","encoder"],"install":[{"cmd":"npm install bmp-js","lang":"bash","label":"npm"},{"cmd":"yarn add bmp-js","lang":"bash","label":"yarn"},{"cmd":"pnpm add bmp-js","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package only provides CommonJS exports. Direct ESM imports like `import bmp from 'bmp-js';` will result in a runtime error or an empty object.","wrong":"import bmp from 'bmp-js';","symbol":"bmp","correct":"const bmp = require('bmp-js');"},{"note":"The `decode` function is a method of the default CommonJS export. It is not available as a named ESM export.","wrong":"import { decode } from 'bmp-js';","symbol":"decode","correct":"const bmp = require('bmp-js');\nconst bmpData = bmp.decode(buffer);"},{"note":"The `encode` function is a method of the default CommonJS export. It is not available as a named ESM export.","wrong":"import { encode } from 'bmp-js';","symbol":"encode","correct":"const bmp = require('bmp-js');\nconst outputBuffer = bmp.encode(bmpData);"}],"quickstart":{"code":"const fs = require('fs');\nconst bmp = require('bmp-js');\n\n// To run this example, ensure you have a 'bit24.bmp' file\n// in the same directory, or create a dummy one.\n\nasync function processBmp() {\n  try {\n    // 1. Decode a BMP file\n    const inputBuffer = fs.readFileSync('bit24.bmp');\n    const bmpData = bmp.decode(inputBuffer);\n\n    console.log('Decoded BMP properties:');\n    console.log(`Width: ${bmpData.width}, Height: ${bmpData.height}`);\n    console.log(`Bits Per Pixel: ${bmpData.bitPP}`);\n    console.log(`Pixel Data Length: ${bmpData.data.length} bytes`);\n\n    // 2. Modify pixel data (e.g., set top-left pixel to solid red)\n    // The `data` property is a byte array ordered by ABGR ABGR ABGR.\n    if (bmpData.data.length >= 4) {\n      bmpData.data[0] = 0x00; // Alpha (ignored in most BMPs, set to 0)\n      bmpData.data[1] = 0x00; // Blue\n      bmpData.data[2] = 0x00; // Green\n      bmpData.data[3] = 0xFF; // Red\n    }\n\n    // 3. Encode modified data back into a 24-bit BMP\n    // Note: bmp-js currently only encodes to 24-bit BMP format.\n    const outputBmpBuffer = bmp.encode({\n      data: bmpData.data,\n      width: bmpData.width,\n      height: bmpData.height\n    });\n\n    fs.writeFileSync('output_modified.bmp', outputBmpBuffer.data);\n    console.log('BMP decoded, modified top-left pixel, and re-encoded to output_modified.bmp');\n\n  } catch (error) {\n    console.error('Error processing BMP:', error.message);\n    if (error.code === 'ENOENT' && error.message.includes('bit24.bmp')) {\n      console.warn(\"Please ensure 'bit24.bmp' exists in the current directory to run this example.\");\n      console.warn(\"You can create a dummy 24-bit BMP or download one for testing.\");\n    }\n  }\n}\n\nprocessBmp();","lang":"javascript","description":"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."},"warnings":[{"fix":"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.","message":"The package is in a pre-1.0 state (version 0.1.0) and appears to be unmaintained since its last update. This implies potential lack of security patches, bug fixes, or compatibility updates for newer Node.js versions or evolving BMP specifications. Use with caution in production environments.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"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');`.","message":"The library exclusively uses CommonJS modules (`require`). It does not provide ESM exports, meaning direct `import` statements will fail or lead to unexpected behavior in ESM-only Node.js environments or modern browser module setups.","severity":"breaking","affected_versions":">=0.1.0"},{"fix":"If you need to encode BMPs with different bit depths or compression, consider using a more feature-rich image processing library.","message":"While `bmp-js` supports decoding various bit depths (1, 4, 8, 16, 24, 32), its encoding functionality is strictly limited to 24-bit BMPs without compression. Attempting to encode other bit depths or compressed formats is not supported.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"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`.","message":"The `data` property returned by `bmp.decode()` represents pixel data in ABGR (Alpha, Blue, Green, Red) byte order, with 4 bytes per pixel. This can be confusing as many image formats use RGBA or BGRA, and standard BMP usually implies BGRA without alpha.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Use the correct CommonJS require syntax to import the module: `const bmp = require('bmp-js');` and then access methods as `bmp.decode(buffer);`.","cause":"Attempting to use `import { decode } from 'bmp-js';` or an incorrect CommonJS require pattern, leading to `bmp` not being the module object.","error":"TypeError: bmp.decode is not a function"},{"fix":"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.","cause":"The specified BMP file does not exist at the given path or the path is incorrect.","error":"Error: ENOENT: no such file or directory, open 'your_file.bmp'"},{"fix":"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 });`.","cause":"The object passed to `bmp.encode()` is missing the `data` property, or its value is `undefined`. Alternatively, `width` or `height` properties might be missing or invalid.","error":"TypeError [ERR_INVALID_ARG_TYPE]: The \"data\" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined"}],"ecosystem":"npm"}