fast-bmp
    Preparing search index...

    fast-bmp

    Zakodium logo

    Maintained by Zakodium

    fast-bmp

    NPM version npm download test coverage license

    A BMP image decoder and encoder.

    npm install fast-bmp
    

    This library only supports V5 headers.

    • binary (1-bit per pixel)
    • greyscale (8-bits per pixel)
    • RGB (24-bits per pixel)
    • RGBA (32-bits per pixel)
    import { encode } from 'fast-bmp';

    // 0 0 0 0 0
    // 0 1 1 1 0
    // 0 1 0 1 0
    // 0 1 1 1 0
    // 0 0 0 0 0
    const data = new Uint8Array([
    0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0,
    ]);
    const imageData = {
    width: 5,
    height: 5,
    data,
    bitsPerPixel: 1,
    components: 1,
    channels: 1,
    };
    // Encode returns a Uint8Array.
    const encoded = encode(imageData);
    fs.writeFileSync('image.bmp', encoded);
    import { decode } from 'fast-bmp';

    // 0 0 0 0 0
    // 0 1 1 1 0
    // 0 1 0 1 0
    // 0 1 1 1 0
    // 0 0 0 0 0
    const buffer = fs.writeFileSync('image.bmp');
    const imageData = decode(buffer);
    /* Returns object:
    {
    width: 5,
    height: 5,
    data: new Uint8Array([
    0, 0, 0, 0, 0,
    0, 1, 1, 1, 0,
    0, 1, 0, 1, 0,
    0, 1, 1, 1, 0,
    0, 0, 0, 0, 0,
    ]),
    bitsPerPixel: 1,
    components: 1,
    channels: 1,
    colorMasks: [0x00ff0000, 0x0000ff00, 0x000000ff],
    compression: 0,
    xPixelsPerMeter: 2835,
    yPixelsPerMeter: 2835,
    }
    */

    MIT