imagemin-most-optimized-png

1.0.6 • Public • Published

imagemin-most-optimized-png

Returns the best optimized image from pngquant, optipng or the original if optimization didn't improve it.

usage

npm i imagemin-most-optimized-png

or

npm i -D imagemin-most-optimized-png

import { readFile, writeFile } from 'fs/promises';
import optimizePNG from "imagemin-most-optimized-png";

const optimze = async path => {
	const data = await readFile(path);
	const optimized = await optimizePNG(data);
	await writeFile("/path/to/dist/image.png", optimized);
} 

optimze("/path/to/source/image.png");

Pass plugin quality levels as options for pngquant and optipng.

import { readFile, writeFile } from 'fs/promises';
import optimizePNG from "imagemin-most-optimized-png";

const options = { 
	// defaults shown
	
	// Array<0...1, 0...1> Instructs pngquant to use the least amount of colors required to meet or exceed the max quality.
	pngquant: [0.5, 0.8], 
	
	// 0-7, 0 - minimal optimization, 7 - 240 trials 
	optipng: 3 
}

const optimze = async path => {
	const data = await readFile(path);
	const optimized = await optimizePNG(data, options);
	await writeFile("/path/to/dist/image.png", optimized);
} 

optimze("/path/to/source/image.png");

Readme

Keywords

none

Package Sidebar

Install

npm i imagemin-most-optimized-png

Weekly Downloads

7

Version

1.0.6

License

MIT

Unpacked Size

10 kB

Total Files

5

Last publish

Collaborators

  • paul-browne