Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@types/pngjs
Advanced tools
TypeScript definitions for pngjs
@types/pngjs provides TypeScript type definitions for the pngjs library, which is used for reading and writing PNG files in Node.js.
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'));
});
Sharp is a high-performance image processing library for Node.js. It supports various image formats including PNG, JPEG, and WebP. Compared to pngjs, Sharp offers more advanced image processing capabilities such as resizing, cropping, and format conversion.
Jimp is an image processing library for Node.js that supports reading and writing various image formats, including PNG. It provides a wide range of image manipulation features such as resizing, cropping, and color adjustments. Jimp is more feature-rich compared to pngjs but may have a steeper learning curve.
Pngjs2 is a fork of pngjs with additional features and improvements. It offers similar functionalities for reading and writing PNG files but with better performance and additional options. It is a good alternative if you need more features or better performance than pngjs.
npm install --save @types/pngjs
This package contains type definitions for pngjs (https://github.com/lukeapage/pngjs).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/pngjs.
These definitions were written by Jason Cheatham, Florian Imdahl, and Piotr Błażejewicz.
FAQs
TypeScript definitions for pngjs
The npm package @types/pngjs receives a total of 424,196 weekly downloads. As such, @types/pngjs popularity was classified as popular.
We found that @types/pngjs demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.