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

png-img

v5.0.1

Published

PNG Image

Downloads

1,076

Readme

png-img

Build Status

Lite self-contained png image processing library for macOS and Linux.

Requirements

Linux

  • Depends on GCC 4.6+

macOs

Windows

Installation

npm install png-img

API

new PngImg(buffer)

Create PngImg object from passed buffer with image.

Arguments:

  • buf - Buffer with image file content.
const fs = require('fs');
const {PngImg} = require('png-img');

const buf = fs.readFileSync('path/to/img.png');
const img = new PngImg(buf);

size()

Get image size as an object.

console.log(img.size());

for 32x32 image will print out:

{ width: 32, height: 32 }

get(x, y)

Get pixel color and alpha.

Returns object:

  • r: red channel (0 to 255)
  • g: green channel (0 to 255)
  • b: blue channel (0 to 255)
  • a: alpha (0 to 255). 0 - transparent
console.log(img.get(0, 0));

will print pixel and color for pixel (0, 0):

{
  r: 100,
  g: 150,
  b: 200,
  a: 255
}

fill(offsetX, offsetY, widht, height, color)

Fill region with passed color. Modifies current image.

Arguments:

  • offsetX - horizontal offset from the left side of the image
  • offsetY - vertical offset from the top side of the image
  • width - region width
  • height - region height
  • color - color as {r,g,b,a} object or as a '#XXXXXX' string

Returns: current image object

Throws if region is not inside the current image

img
  .fill(0, 0, 16, 16, '#00ffFF') // fill with cyan
  .fill(16, 16, 16, 16, {r: 0, g: 255, b: 255, a: 127}); // fill with half-transparent cyan

set(x, y, color)

Same as fill(x, y, 1, 1, color)

crop(offsetX, offsetY, widht, height)

Crop image. Modifies current image.

Arguments:

  • offsetX - horizontal offset from the left side of the image
  • offsetY - vertical offset from the top side of the image
  • width - new width
  • height - new height

Returns: current image object

Throws if new image is not inside the current image.

img
    .crop(0, 0, 16, 16)
    .crop(8, 8, 8, 8);

setSize(width, height)

Sets new image size. Modifies current image.

Arguments:

  • width - new width
  • height - new height

Returns: current image object

If new size is less or equal than current size, than crop will be performed.

Note: this method doesn't strech current image, it just sets new size. If new dimension is less than previous than image will be cut. If new dimension is greater than previous than image will be extended with black area.

var size = img.size();
img
  .setSize(size.width/2, size.height*2);

insert(img, offsetX, offsetY)

Inserts image into specified place.

Arguments:

  • img - image to insert. Should be a PngImg object
  • offsetX - horizontal offset from the left side of the image
  • offsetY - vertical offset from the top side of the image

Join to images (pretend that they have same witdh):

var otherImg = new PngImg(/*...*/)
img
 .setSize(img.size().width, img.size().height + otherImg.size().height)
 .insert(otherImg, 0, img.size().height);

rotateRight()

Rotates image 90 degrees clockwise

rotateLeft()

Rotates image 90 degress counterclockwise

save(file)

Save image to file. Asynchronous operation.

Arguments:

  • file - path to file to save image

Overwrites existing file.

await img.save('path/to/file.png');

Build

npm run build

This will build native node extension and place it to the compiled directory

Release

  1. Up version in package json, create tag, and push it to repo. Note: Do not publish the package.
$ npm version <patch|minor|major>
$ git push && git push --tags
  1. Go to tags page and create release from pushed tag.
  2. Wait for the release workflow to finish. See the actions page to find the workflow.

Vagrant

Use Vagrant to build and test on Linux and Windows from macOS.

Tested with Vagrant 1.7 and VirtualBox 4.3.

  1. Install Vagrant and VirtualBox.
  2. Create Windows vagrant box (see howto)
  3. Run vagrant up --provider virtualbox
  4. Specify OS env variable to run and test on specific platform:
  • npm run build, npm test - current platform
  • OS=linux npm test - Ubuntu 14.04
  • OS=linux-old npm test - Ubuntu 12.04
  • OS=win npm test - Windows
  • OS=all npm test - all