Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pngjs

Package Overview
Dependencies
Maintainers
2
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pngjs

PNG encoder/decoder in pure JS, supporting any bit size & interlace, async & sync with full test suite.

  • 3.3.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.4M
decreased by-57.66%
Maintainers
2
Weekly downloads
 
Created

What is pngjs?

The pngjs npm package is a pure JavaScript implementation for PNG encoding and decoding in Node.js. It allows for reading and writing PNG images in a non-blocking and streaming way, which is useful for applications that need to handle image data directly.

What are pngjs's main functionalities?

Reading PNG files

This code demonstrates how to read a PNG file using pngjs. It creates a read stream from a file, pipes it through the PNG decoder, and logs the image's width and height once it's parsed.

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

fs.createReadStream('input.png')
  .pipe(new PNG())
  .on('parsed', function() {
    console.log('Image width:', this.width, 'Image height:', this.height);
  });

Writing PNG files

This code snippet shows how to create a new PNG image with a specific width and height, fill it with white color, and then write it to a file. It demonstrates the package's ability to write PNG files.

const fs = require('fs');
const PNG = require('pngjs').PNG;
const png = new PNG({ width: 10, height: 10, filterType: -1 });

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

    png.data[idx] = 255; // red
    png.data[idx + 1] = 255; // green
    png.data[idx + 2] = 255; // blue
    png.data[idx + 3] = 255; // alpha (opacity)
  }
}

png.pack().pipe(fs.createWriteStream('output.png'));

Other packages similar to pngjs

Keywords

FAQs

Package last updated on 19 Apr 2018

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