Registry / serialization / bmp-ts

bmp-ts

JSON →
library1.0.9jsnpmunverified

bmp-ts is a pure TypeScript library designed for encoding and decoding BMP image files. It currently stands at version 1.0.9, with a release cadence focused on addressing bug fixes and minor enhancements. The library distinguishes itself by offering comprehensive support for all common BMP bit depths, including 1-bit, 4-bit, 8-bit, 16-bit, 24-bit, and 32-bit images. It provides granular control over BMP header properties during the encoding process and offers an optional `toRGBA` conversion during decoding for compatibility with other image processing libraries. While it supports various compression methods for decoding, a key limitation is the lack of compression support during encoding, meaning output files will always be uncompressed.

npm install bmp-ts
INSTALL
IMPORT
SIG · BMP-TS
B
bmp-ts
serializationjavascriptv1.0.9
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

bmp
import bmp from 'bmp-ts';
import { decode, encode } from 'bmp-ts';
The primary `bmp` object is a default export, containing `decode` and `encode` methods.
bmp (CommonJS)
const bmp = require('bmp-ts').default;
const bmp = require('bmp-ts');
In CommonJS, the default export must be explicitly accessed via `.default`.
BmpData (Type)
import type { BmpData, BmpHeader } from 'bmp-ts';
TypeScript types for the decoded image data and header are available for explicit import.

Demonstrates how to decode an existing BMP file and encode a new BMP image from raw pixel data using `bmp-ts`.

import bmp from 'bmp-ts'; import * as fs from 'fs'; // --- Decoding a BMP image --- // Ensure 'example.bmp' exists in the execution directory for this to run. // You can replace this with any Buffer containing BMP data. try { const bmpBuffer = fs.readFileSync('example.bmp'); const decodedBmpData = bmp.decode(bmpBuffer, { toRGBA: true }); console.log('Decoded BMP Header:', decodedBmpData.header); console.log('Decoded BMP Data length:', decodedBmpData.data.length); console.log('Decoded BMP dimensions:', decodedBmpData.header.width, 'x', decodedBmpData.header.height); } catch (error) { console.error('Error decoding example.bmp:', error); } // --- Encoding a new BMP image --- // Create a dummy image buffer (e.g., a 10x10 white image with alpha) const width = 10; const height = 10; const pixelData = Buffer.alloc(width * height * 4, 255); // RGBA white pixels const bmpDataToEncode = { data: pixelData, bitPP: 32, // 32-bit RGBA width: width, height: height // Optional: other BMP header fields can be specified here. }; const encodedRawData = bmp.encode(bmpDataToEncode); fs.writeFileSync('./output.bmp', encodedRawData.data); console.log('Encoded 10x10 32-bit white BMP saved to output.bmp');
Debug
Known issues
breakingVersion 1.0.0 introduced breaking changes to the API. Users upgrading from pre-1.0 versions will need to adapt their code to the new interface, which standardized the `decode` and `encode` methods.
fix
Review the new API usage in the README or package documentation for correct method signatures and object structures.
affects: >=1.0.0
gotchaThe `encode` function in `bmp-ts` currently does not support any compression methods. All output BMP files generated by encoding will be uncompressed, which can result in larger file sizes.
fix
Be aware that encoded files will be larger. If compressed BMPs are required, external tools or post-processing will be necessary.
affects: >=1.0.0
gotchaCommonJS users must access the default export of `bmp-ts` via `.default` (e.g., `require('bmp-ts').default`). Directly using `require('bmp-ts')` will not expose the `decode` and `encode` methods directly, leading to runtime errors.
fix
Always append `.default` when importing `bmp-ts` in CommonJS environments: `const bmp = require('bmp-ts').default;`
affects: >=1.0.0
gotchaPrior to version 1.0.5, `bmp-ts` had a bug that caused decoding errors or incorrect image data when processing bottom-up BMP images.
fix
Upgrade to `bmp-ts@1.0.5` or a newer version to ensure correct decoding of all BMP image orientations.
affects: <1.0.5
gotchaVersions prior to 1.0.4 experienced issues with CommonJS module resolution, which could prevent the package from being imported correctly in certain Node.js environments.
fix
Update to `bmp-ts@1.0.4` or a later version to resolve CommonJS import problems and ensure proper module loading.
affects: <1.0.4
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'decode')
This error typically occurs in CommonJS environments when attempting to call `bmp.decode` (or `bmp.encode`) after importing `bmp-ts` without accessing the default export.
fix
In CommonJS, explicitly use `.default`: `const bmp = require('bmp-ts').default;`.
TypeError: bmp.decode is not a function
This can happen in ESM if `import * as bmp from 'bmp-ts';` is used, treating the module as a namespace object, when `decode` is a property of the default export, not a named export.
fix
Use `import bmp from 'bmp-ts';` to import the default export directly.
Property 'data' is missing in type '{ data: Buffer; bitPP: number; width: number; height: number; }' but required in type 'BmpDataInput'.
A TypeScript compilation error indicating that the object passed to `bmp.encode` is missing required properties or has incorrect types.
fix
Ensure the object passed to `bmp.encode` strictly conforms to the `BmpDataInput` interface, including `data` (Buffer), `width` (number), `height` (number), and `bitPP` (number).
The image data is not correctly decoded and appears flipped vertically.
This is a known issue for bottom-up BMP images in versions prior to `v1.0.5`.
fix
Upgrade `bmp-ts` to version `1.0.5` or newer. If upgrading isn't possible, manual image data manipulation might be required to flip the image vertically after decoding.
Upgrade
Version history
1.0.9latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
9
Amazon
1
OpenAI (training)
1
Resources
bmp-ts — npm install bmp-ts · libregistry