Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
pngquant-bin
Advanced tools
`pngquant` wrapper that makes it seamlessly available as a local dependency
The pngquant-bin npm package provides a Node.js wrapper for the pngquant command-line tool, which is used to compress PNG images. It allows developers to reduce the file size of PNG images while maintaining a balance between quality and compression.
Compress PNG images
This feature allows you to compress PNG images by specifying the quality range. The code sample demonstrates how to use the pngquant-bin package to compress an image named 'input.png' and save the compressed version as 'output.png'.
const pngquant = require('pngquant-bin');
const { execFile } = require('child_process');
execFile(pngquant, ['--quality=65-80', 'input.png', '-o', 'output.png'], err => {
if (err) {
throw err;
}
console.log('Image compressed successfully');
});
Batch processing of PNG images
This feature allows you to compress multiple PNG images in a directory. The code sample demonstrates how to read all files in the 'images' directory, compress each one, and save the compressed versions in the 'compressed_images' directory.
const pngquant = require('pngquant-bin');
const { execFile } = require('child_process');
const fs = require('fs');
const path = require('path');
const inputDir = 'images';
const outputDir = 'compressed_images';
fs.readdir(inputDir, (err, files) => {
if (err) {
throw err;
}
files.forEach(file => {
const inputFile = path.join(inputDir, file);
const outputFile = path.join(outputDir, file);
execFile(pngquant, ['--quality=65-80', inputFile, '-o', outputFile], err => {
if (err) {
throw err;
}
console.log(`${file} compressed successfully`);
});
});
});
The imagemin-pngquant package is a plugin for Imagemin that uses pngquant to compress PNG images. It offers similar functionality to pngquant-bin but is designed to be used within the Imagemin ecosystem, which provides a more extensive set of image optimization tools.
The pngcrush-bin package provides a Node.js wrapper for the pngcrush command-line tool, which is another utility for optimizing PNG images. While pngcrush focuses on reducing file size by eliminating unnecessary data, it may not achieve the same level of compression as pngquant.
The optipng-bin package offers a Node.js wrapper for the OptiPNG command-line tool, which is used to optimize PNG images. OptiPNG performs lossless compression, meaning it reduces file size without affecting image quality, but it may not achieve the same compression ratios as pngquant.
pngquant
is a PNG compressor that significantly reduces file sizes by converting images to a more efficient 8-bit PNG format
You probably want imagemin-pngquant
instead.
npm install pngquant-bin
Make sure you have the correct version of libimagequant.
# via Homebrew for macOS
brew install libimagequant
# via apt-get for Debian distributions
sudo apt-get install libimagequant-dev
import {execFile} from 'node:child_process';
import pngquant from 'pngquant-bin';
execFile(pngquant, ['-o', 'output.png', 'input.png'], error => {
console.log('Image minified!');
});
npm install --global pngquant-bin
pngquant --help
The Linux binaries are statically linked so they should work on all Linux distributions. To recompile them:
sudo apt-get install libpng-dev
./configure CFLAGS=-static && make && cp pngquant pngquant-64
pwd
:/source i386/debian:9.3 bashFAQs
`pngquant` wrapper that makes it seamlessly available as a local dependency
The npm package pngquant-bin receives a total of 307,101 weekly downloads. As such, pngquant-bin popularity was classified as popular.
We found that pngquant-bin demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 open source maintainers 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.