Socket
Socket
Sign inDemoInstall

@types/pngjs

Package Overview
Dependencies
2
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @types/pngjs

TypeScript definitions for pngjs


Version published
Weekly downloads
370K
decreased by-15.79%
Maintainers
1
Install size
698 kB
Created
Weekly downloads
 

Package description

What is @types/pngjs?

@types/pngjs provides TypeScript type definitions for the pngjs library, which is used for reading and writing PNG files in Node.js.

What are @types/pngjs's main functionalities?

Reading PNG files

This feature allows you to read PNG files and access their properties such as width and height.

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

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

Writing PNG files

This feature allows you to create and write PNG files. The example creates a 100x100 red PNG image.

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

const png = new PNG({ width: 100, height: 100 });

for (let y = 0; y < png.height; y++) {
  for (let x = 0; x < png.width; x++) {
    const idx = (png.width * y + x) << 2;
    png.data[idx] = 255;
    png.data[idx + 1] = 0;
    png.data[idx + 2] = 0;
    png.data[idx + 3] = 255;
  }
}

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

Manipulating PNG data

This feature allows you to manipulate the pixel data of a PNG file. The example inverts the colors of the input PNG.

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

fs.createReadStream('in.png')
  .pipe(new PNG())
  .on('parsed', function() {
    for (let y = 0; y < this.height; y++) {
      for (let x = 0; x < this.width; x++) {
        const idx = (this.width * y + x) << 2;
        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];
      }
    }
    this.pack().pipe(fs.createWriteStream('out.png'));
  });

Other packages similar to @types/pngjs

Readme

Source

Installation

npm install --save @types/pngjs

Summary

This package contains type definitions for pngjs (https://github.com/lukeapage/pngjs).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/pngjs.

Additional Details

  • Last updated: Mon, 11 Nov 2019 23:24:43 GMT
  • Dependencies: @types/node
  • Global values: none

Credits

These definitions were written by Jason Cheatham (https://github.com/jason0x43), and Florian Keller (https://github.com/ffflorian).

FAQs

Last updated on 11 Nov 2019

Did you know?

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc