
Security News
Open Source CAI Framework Handles Pen Testing Tasks up to 3,600× Faster Than Humans
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
grunt-pngmin
Advanced tools
Grunt plugin to compress png images with pngquant.
This plugin requires Grunt >=1.0.0
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-pngmin --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks("grunt-pngmin");
Windows, Linux and Mac OSX is supported out of the box.
In your project's Gruntfile, add a section named pngmin
to the data object passed into grunt.initConfig()
.
grunt.initConfig({
pngmin: {
options: {
// Task-specific options go here.
},
your_target: {
// Target-specific file lists and/or options go here.
},
},
});
Type: Number
Default value: 4
How many executables will be spawned in parallel.
Type: String
Default value: '-fs8.png'
The file extension after the quantization.
Type: String
, Object
or Array
Default value: null
Instructs pngquant to use the least amount of colors required to meet or exceed the max quality. If conversion results in quality below the min quality the image won't be saved. Specify quality like that:
'min-max'
{min: min, max: max}
[min, max]
min and max are numbers in range 0 (worst) to 100 (perfect), similar to JPEG.
For example as object: {min: 60, max: 80}
.
Type: Boolean
Default value: false
Should existing files be overwritten by the optimized version? Be careful with this option if you need the original files!
Type: Number
Default value: 3
Speed/quality trade-off from 1 (brute-force) to 10 (fastest). Speed 10 has 5% lower quality, but is 8 times faster than the default.
Type: Boolean
Default value: false
Workaround for IE6, which only displays fully opaque pixels. pngquant will make almost-opaque pixels fully opaque and will avoid creating new transparent colors.
Type: String
Default value: 'pngquant'
in your PATH
or 'bin/pngquant'
This option is just for users where the pngquant-bin package could not be installed correctly. Normally you don't need this!
The pngquant executable which will be spawned. If the pngquant binary is not found in PATH
the default fallback is 'bin/pngquant'
, but this option has always precedence.
Type: Boolean
Default value: true
If pngquant exits with status 99 (ie it was not able to compress with the specified quality option), allow pngmin to try again without quality option.
Type: Boolean
Default value: false
If nofs
is set to true
the Floyd-Steinberg dithering will be disabled.
Type: Boolean
Default value: true
Causes the grunt
command to also fail in case an error is encountered. For details, just add --stack
to your grunt
command.
In this example image.png
will be optimized, copied to dest
folder and renamed to image-fs8.png
.
grunt.initConfig({
pngmin: {
compile: {
options: {},
files: [
{
src: "path/to/image.png",
dest: "dest/",
},
],
},
},
});
In this example image.png
will be optimized and copied to dest
folder.
grunt.initConfig({
pngmin: {
compile: {
options: {
ext: ".png",
},
files: [
{
src: "path/to/image.png",
dest: "dest/",
},
],
},
},
});
In this example image.png
gets overwritten by the optimized version, so use force option carefully!
grunt.initConfig({
pngmin: {
compile: {
options: {
ext: ".png",
force: true,
},
files: [
{
src: "path/to/image.png",
dest: "path/to/",
},
],
},
},
});
In this example all images in the folder path/to/images/
and its subfolders will be optimized and copied to dest
while preserving the directory structure.
See http://gruntjs.com/configuring-tasks#building-the-files-object-dynamically for more options.
grunt.initConfig({
pngmin: {
compile: {
options: {
ext: ".png",
},
files: [
{
expand: true, // required option
src: ["**/*.png"],
cwd: "path/to/images/", // required option
dest: "dest/",
},
],
},
},
});
This is a complex example with a lot of options set:
grunt.initConfig({
pngmin: {
compile: {
options: {
concurrency: 8, // specify how many exucutables get spawned in parallel
ext: ".png", // use .png as extension for the optimized files
quality: "65-80", // output quality should be between 65 and 80 like jpeg quality
speed: 10, // pngquant should be as fast as possible
iebug: true, // optimize image for use in Internet Explorer 6
nofs: true, // disable dithering
},
files: [
{
src: "path/to/images/*.png",
dest: "dest/",
},
{
src: "path/to/other/images/*.png",
dest: "another/dest/",
},
],
},
},
});
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.
When writing unit tests, perform the following:
Node 20+
setup and installed.npm install
npm run test
failOnError
option is now true
by defaultpngquant
and added option failOnError
. To begin failing on errors, please set failOnError
to true
. (2020-07-10 via #21)PATH
, otherwise uses fallback, but options.binary has always precedenceforce
option is false and the file already exists at the destination pngquant doesn't get spawnedFAQs
Grunt plugin to compress png images with pngquant.
The npm package grunt-pngmin receives a total of 381 weekly downloads. As such, grunt-pngmin popularity was classified as not popular.
We found that grunt-pngmin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 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.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.