Socket
Socket
Sign inDemoInstall

pngjs

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pngjs

Simple PNG encoder/decoder


Version published
Weekly downloads
8.1M
decreased by-1.68%
Maintainers
1
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 18 Aug 2012

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