npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bitmap-manipulation

v2.0.0

Published

Bitmap manipulation (reading file, drawing shapes and text)

Downloads

254

Readme

bitmap-manipulation

Node.js package for in-memory bitmap manipulation.

Build Status

Features

  • Creating bitmaps (1, 2 or 4 bytes per pixel, in big- or little-endian)
  • Changing the color depth
  • Reading 8-bit .bmp files
  • Saving .bmp files
  • Getting/setting pixels
  • Change the color of every pixel in a specific color
  • Drawing rectangles (horizontal gradient in greyscale possible)
  • Drawing circles/ellipses
  • Inverting the bitmap
  • Drawing a bitmap or a portion of it on a bitmap
  • Drawing text with a bitmap font

Example

"use strict";

const bitmapManipulation = require("bitmap-manipulation");

// Create bitmap
let bitmap = new bitmapManipulation.Bitmap(400, 300);

// Draw rectangle with border
bitmap.drawFilledRect(10, 10, 100, 50, 0x00, 0xff);

// Draw another bitmap with some source pixels in a specific color handled as transparent
let overlayBitmap = Bitmap.fromFile("overlayBitmap.bmp");
bitmap.drawBitmap(overlayBitmap, 200, 0, overlayBitmap.getPalette().indexOf(0xff00ff/*magenta*/));

// Draw text
let font = new bitmapManipulation.Font("P:\\ath\\to\\Font.json");
font.setSize(20);
bitmap.drawText(font, "Hello World!", 10, 100);

// The raw pixel data can also be processed in a user-specific way
let bitmapData = bitmap.data();  // Return a Node.js Buffer

Image formats

With release 2.0.0, drawing and pixel storage are separated. This way, different image formats (e.g. RGB with interleaved or planar storage) can be used by providing a Canvas implementantion to the Bitmap constructor.

The following canvas implementations are included in the distribution:

|Class name |Description | |-------------------------|------------------------------------------------------| |canvas.Grayscale |Grayscale pixel values | |canvas.RGB |RGB pixel values, interleaved storage (R-G-B-R-G-B) | |canvas.PlanarRGB |RGB pixel values, planar storage (R-R-G-G-B-B) | |canvas.InterleavedStorage|Interleaved storage of values with multiple components| |canvas.PlanarStorage |Planar storage of values with multiple components | |canvas.Base |Base class, use this for custom implementations |

Note that drawing gradients using drawGradientRect() only produces sensible results on a grayscale canvas.

Example: RGB image with 8 bits per pixel per color channel

const bitmapManipulation = require("bitmap-manipulation");

// Create a canvas that stores interleaved RGB pixels 
let canvas = new bitmapManipulation.canvas.RGB(400, 300, 1);

// Create a bitmap that uses this canvas for pixel storage
let bitmap = new bitmapManipulation.Bitmap(canvas);

// Draw a rectangle filled with cyan and a purple border.
// Note that the RGB canvas requires pixel values to be RGB arrays
bitmap.drawFilledRect(10, 10, 100, 50, [255, 0, 255], [0, 255, 255]);

// Get bytes of the image
let imageData = bitmap.data();

Example: RGBA image with 16 bits per pixel per color channel

const bitmapManipulation = require("bitmap-manipulation");

// Create a canvas that stores interleaved RGBA pixels 
let canvas = new bitmapManipulation.canvas.Interleaved(400, 300, 4, 2);

// Create a bitmap that uses this canvas for pixel storage
let bitmap = new bitmapManipulation.Bitmap(canvas);

// Draw a rectangle filled with half-opaque cyan and a solid purple border.
let halfOpaqueCyan = [0, 65535, 65535, 32767];
let solidPurple = [65535, 0, 65535, 65535];
bitmap.drawFilledRect(10, 10, 100, 50, halfOpaqueCyan, solidPurple);

// Get bytes of the image
let imageData = bitmap.data();

BMP file support

Loading from and writing to BMP files is supported using the subclass BMPBitmap. See examples/Drawing for details.

Documentation

The documentation can be generated from the source code by:

jsdoc index.js

License

MIT