Skip to content

Commit

Permalink
Fix the quality option
Browse files Browse the repository at this point in the history
It's now an array of a `min` and a `max` element.

Fixes #48
  • Loading branch information
sindresorhus committed Jan 7, 2019
1 parent fdac781 commit 0e0edd2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ module.exports = (options = {}) => input => {
}

if (typeof options.quality !== 'undefined') {
ow(options.quality, ow.number.inRange(0, 1));
args.push('--quality', Math.round(options.quality * 100));
ow(options.quality, ow.array.length(2).ofType(ow.number.inRange(0, 1)));
const [min, max] = options.quality;
args.push('--quality', `${Math.round(min * 100)}-${Math.round(max * 100)}`);
}

if (typeof options.dithering !== 'undefined') {
Expand Down
5 changes: 3 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ Remove optional metadata.

##### quality

Type: `number`<br>
Values: `0...1`
Type: `Array<min: number, max: number>`<br>
Values: `Array<0...1, 0...1>`<br>
Example: `[0.3, 0.5]`

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
Expand Down
4 changes: 2 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test('support pngquant options', async t => {
const buffer = await fs.readFileSync(path.join(__dirname, 'fixture.png'));
const data = await imageminPngquant({
speed: 10,
quality: 1
quality: [0.8, 1]
})(buffer);
t.true(data.length > 30000);
t.true(isPng(data));
Expand All @@ -38,7 +38,7 @@ test('skip optimizing a non-PNG file', async t => {

test('skip optimizing a fully optimized PNG', async t => {
const buffer = await fs.readFileSync(path.join(__dirname, 'fixture-no-compress.png'));
const data = await imageminPngquant({quality: 1})(buffer);
const data = await imageminPngquant({quality: [0.8, 1]})(buffer);
t.is(data.length, buffer.length);
t.true(isPng(data));
});

0 comments on commit 0e0edd2

Please sign in to comment.