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

node-png-mtr

v0.5.2

Published

Simple PNG encoder/decoder

Downloads

7

Readme

About

Simple PNG encoder/decoder for Node.js with no native dependencies. This is a alternative from pkrumins original code.

Installation

$ npm install node-png-mtr 

Example

var fs = require('fs'),
    PNG = require('pngjs').PNG;

fs.createReadStream('in.png')
    .pipe(new PNG({
        filterType: 4
    }))
    .on('parsed', function() {

        for (var y = 0; y < this.height; y++) {
            for (var x = 0; x < this.width; x++) {
                var idx = (this.width * y + x) << 2;

                // invert color
                this.data[idx] = 255 - this.data[idx];
                this.data[idx+1] = 255 - this.data[idx+1];
                this.data[idx+2] = 255 - this.data[idx+2];

                // and reduce opacity
                this.data[idx+3] = this.data[idx+3] >> 1;
            }
        }

        this.pack().pipe(fs.createWriteStream('out.png'));
    });

For more examples see examples folder.

Documentation

As input any color type is accepted (grayscale, rgb, palette, grayscale with alpha, rgb with alpha) but 8 bit per sample (channel) is the only supported bit depth. Interlaced mode is not supported.

Supported ancillary chunks

  • gAMA - gamma,
  • tRNS - transparency (but only for paletted image)

Class: PNG

PNG is readable and writable Stream.

Options

  • width - use this with height if you want to create png from scratch
  • height - as above
  • checkCRC - whether parser should be strict about checksums in source stream (default: true)
  • deflateChunkSize - chunk size used for deflating data chunks, this should be power of 2 and must not be less than 256 and more than 32*1024 (default: 32 kB)
  • deflateLevel - compression level for delate (default: 9)
  • deflateStrategy - compression strategy for delate (default: 3)
  • filterType - png filtering method for scanlines (default: -1 => auto, accepts array of numbers 0-4)

Event "metadata"

function(metadata) { } Image's header has been parsed, metadata contains this information:

  • width image size in pixels
  • height image size in pixels
  • palette image is paletted
  • color image is not grayscale
  • alpha image contains alpha channel

Event: "parsed"

function(data) { } Input image has been completly parsed, data is complete and ready for modification.

Event: "error"

function(error) { }

png.parse(data, [callback])

Parses PNG file data. Alternatively you can stream data to instance of PNG.

Optional callback is once called on error or parsed. The callback gets two arguments (err, data).

Returns this for method chaining.

png.pack()

Starts converting data to PNG file Stream.

Returns this for method chaining.

png.bitblt(dst, sx, sy, w, h, dx, dy)

Helper for image manipulation, copies rectangle of pixels from current image (sx, sy, w, h) to dst image (at dx, dy).

Returns this for method chaining.

Property: width

Width of image in pixels

Property: height

Height of image in pixels

Property: data

Buffer of image pixel data. Every pixel consists 4 bytes: R, G, B, A (opacity).

Property: gamma

Gamma of image (0 if not specified)

Changelog

0.5.0 - Jan 20 2024

  • First version

License

(The MIT License)

Copyright (c) 2012 Kuba Niegowski

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.