Skip to content

Commit

Permalink
Set interlacing to 0 by default, add tests and improve docs
Browse files Browse the repository at this point in the history
  • Loading branch information
kevva committed Oct 4, 2019
1 parent ef42c2d commit d439590
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ module.exports = options => async buffer => {
arguments_.push('-nb');
}

if (options.interlaced) {
arguments_.push('-i', '1');
if (typeof options.interlaced === 'boolean') {
arguments_.push('-i', options.interlaced ? '1' : '0');
}

if (!options.colorTypeReduction) {
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ Apply palette reduction.

##### interlaced

Type: `boolean`<br>
Type: `boolean | undefined | null`<br>
Default: `false`

Make images interlaced (progressive rendering). Interlaced images look better when they're loaded partially, but usually interlace makes compression less efficient.
Enable [Adam7](https://en.wikipedia.org/wiki/Adam7_algorithm) PNG interlacing on any images that are processed. Interlaced images look better when they're loaded partially, but usually interlace makes compression less efficient. Set to `undefined or `null` to keep the same interlacing as the input image.

##### errorRecovery

Expand Down
21 changes: 21 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,24 @@ test('errorRecovery explicit', async t => {
test('errorRecovery is set to false', async t => {
await t.throwsAsync(optipng({errorRecovery: false})(fixtureBroken));
});

test('interlaced is set to true', async t => {
const [data1, data2] = await Promise.all([
optipng({interlaced: true})(fixture),
optipng()(fixture)
]);

t.true(isPng(data1));
t.true(data1.length > data2.length);
});

test('interlaced is set to undefined and null', async t => {
const [data1, data2, data3] = await Promise.all([
optipng({interlaced: undefined})(fixture),
optipng({interlaced: null})(fixture),
optipng({interlaced: true})(fixture)
]);

t.true(isPng(data1) && isPng(data2));
t.true(data1.length === data2.length && data1.length < data3.length);
});

0 comments on commit d439590

Please sign in to comment.