Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report
Generated on May 8, 2024 via pnpm

pngjs 7.0.0

PNG encoder/decoder in pure JS, supporting any bit size & interlace, async & sync with full test suite.
Package summary
Share
0
issues
1
license
1
MIT
Package created
18 Aug 2012
Version published
20 Feb 2023
Maintainers
1
Total deps
1
Direct deps
0
License
MIT

Issues

0
This package has no issues

Licenses

MIT License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
sublicense
private-use
Cannot
hold-liable
Must
include-copyright
include-license
1 Packages, Including:
pngjs@7.0.0
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

0
All Dependencies CSV
β“˜ This is a list of pngjs 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities

Visualizations

Frequently Asked Questions

What does pngjs do?

PNGJS is a pure JavaScript PNG encoder and decoder used in Node.js with zero dependencies. This library supports any bit size from 1,2,4 & 16, interlace, async and sync files. It brings enhancements over the original pngjs, such as support for reading tTRNS transparent colours and writing a variety of color types. Notably, a synchronous interface alongside the asynchronous one is provided, and the API is compatible with pngjs and node-pngjs. Although it is highly functional, it does not offer support for extended PNG, such as animation or writing in colortype 3 (indexed color).

How do you use pngjs?

To use pngjs, you first have to install it via npm using the command npm install pngjs --save. Once installed, you can include it in your project by importing PNG from pngjs. Here's an example of how to use it:

const fs = require("fs");
const PNG = require("pngjs").PNG;

fs.createReadStream("in.png")
  .pipe(
    new PNG({
      filterType: 4,
    })
  )
  .on("parsed", function () {
    for (let y = 0; y < this.height; y++) {
      for (let x = 0; x < this.width; x++) {
        let 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"));
  });

In this block of code, the script reads a PNG image "in.png", inverts its colors and reduces opacity, then writes the output to "out.png".

Where are the pngjs docs?

The documentation for pngjs which provides the detailed description, features, and code usage examples, can be found on the GitHub repository of the pngjs project. The readme file on the GitHub page serves as the official documentation and provides all the necessary details needed to use this package. It is well-structured, offering a comparison table with other similar packages, details installation process, usage examples, and both Async and Sync API references, making it very straightforward to use and integrate in your JavaScript projects.