New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

sharp-bmp

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sharp-bmp

Bmp encoder and decoder for sharp base on bmp-js.

  • 0.1.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.3K
increased by25.68%
Maintainers
1
Weekly downloads
 
Created
Source

sharp-bmp

Bmp encoder and decoder for sharp base on bmp-js.

Install

npm install sharp-bmp

Usage

Create an instance of sharp from a BMP image

const bmp = require("sharp-bmp");

bmp.sharpFromBmp("input.bmp", {
  // sharp constructor options
}) // returns an instance of sharp
  .toFile("output.png");

Write output image data to a BMP file

const sharp = require("sharp");
const bmp = require("sharp-bmp");

const image = sharp("input.jpg");

bmp.sharpToBmp(image, "output.bmp")
  .then((info) => {
    console.log(info); // { size, width, height }
  })
  .catch((err) => {
    console.error(err);
  });

Decode BMP

const fs = require("fs");
const sharp = require("sharp");
const bmp = require("sharp-bmp");

const buffer = fs.readFileSync("input.bmp");
const bitmap = bmp.decode(buffer);

sharp(bitmap.data, {
  raw: {
    width: bitmap.width,
    height: bitmap.height,
    channels: 4,
  },
})
  .toFile("output.png");

Encode BMP

const fs = require("fs");
const sharp = require("sharp");
const bmp = require("sharp-bmp");

(async () => {
  const image = sharp("input.jpg");
  const { data, info } = await image
    // If the image has alpha transparency channel
    .flatten({ background: "#ffffff" })
    // If the image has no alpha transparency channel
    .ensureAlpha()
    .raw()
    .toBuffer({ resolveWithObject: true });
  const bitmap = {
    data,
    width: info.width,
    height: info.height,
  };
  const rawData = bmp.encode(bitmap);
  fs.writeFileSync("output.bmp", rawData.data);

  console.log(rawData.data.length); // size of output.bmp
})();

Change Log

0.1.3

  • Merge alpha transparency channel with a white background

0.1.4

  • sharpFromBmp(input, options) support Buffer input.

0.1.5

  • sharpFromBmp(input, options, resolveWithObject) add the third option, if true, will return an object with decoding info, default by false
  • Update index.d.ts

Keywords

FAQs

Package last updated on 04 Aug 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