Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@3846masa/bmp

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@3846masa/bmp

Create a BMP (w/ alpha channel) binary from RGBA raw bytes like ImageData.

  • 1.1.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

@3846masa/bmp

banner

npm-badge mit-license-badge

Create a BMP (w/ alpha channel) binary from RGBA raw bytes like ImageData.

  • faster than other libraries (e.g. bmp-js)
  • tiny size (basic: ~ 500 bytes, webworker: ~ 700 bytes)
  • supports alpha channel

Table of Contents

Usage

CDN

Basic

basic codesandbox-badge

See ./examples/basic.

<script type="module">
  import { convert } from 'https://unpkg.com/@3846masa/bmp/lib/convert.mjs';

  const canvas = document.getElementById('canvas');
  const bmpImg = document.getElementById('bmp');

  function main() {
    const ctx = canvas.getContext('2d');

    const raw = ctx.getImageData(0, 0, canvas.width, canvas.height);
    const bmpBinary = convert(raw);
    const blob = new Blob([bmpBinary], { type: 'image/bmp' });

    bmpImg.src = URL.createObjectURL(blob);
  }

  main();
</script>
WebWorker

webworker codesandbox-badge

See ./examples/webworker.

<script type="module">
  import { convert } from 'https://unpkg.com/@3846masa/bmp/lib/worker.mjs';

  const canvas = document.getElementById('canvas');
  const bmpImg = document.getElementById('bmp');

  async function main() {
    const ctx = canvas.getContext('2d');

    const raw = ctx.getImageData(0, 0, canvas.width, canvas.height);
    const bmpBinary = await convert(raw);
    const blob = new Blob([bmpBinary], { type: 'image/bmp' });

    bmpImg.src = URL.createObjectURL(blob);
  }

  main().catch(console.error);
</script>
No module

no-module codesandbox-badge

See ./examples/canvas-to-blob.

<script src="https://unpkg.com/@3846masa/bmp/lib/polyfill.js"></script>
<script>
  const canvas = document.getElementById('canvas');
  const bmpImg = document.getElementById('bmp');

  function main() {
    canvas.toBlob(callback, 'image/bmp');

    function callback(blob) {
      bmpImg.src = URL.createObjectURL(blob);
    }
  }

  main();
</script>

Using via bundler

bundlephobia

npm i @3846masa/bmp
import { convert } from '@3846masa/bmp';

API

convert({ width, height, data }, options?)

Convert RGBA raw bytes like ImageData to a BMP binary.

In worker.mjs, this function returns Promise.

widthnumber
heightnumber
dataUint8Array | Uint8ClampedArray
options.strictboolean
ReturnsUint8Array | Promise<Uint8Array>

HTMLCanvasElement.prototype.toBlob(callback, type)

callback(blob: Blob) => any
type'image/bmp'

Contributing

PRs accepted.

License

MIT (c) 3846masa

Keywords

FAQs

Package last updated on 27 Feb 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc