Skip to content

Commit

Permalink
Fix setting WebP effort to 0 in constructor #3259
Browse files Browse the repository at this point in the history
Setting WebP effort to 0 in the constructor caused effort to use the
default value of 4.
  • Loading branch information
AlexanderTheGrey committed Jun 15, 2022
1 parent b10d8f8 commit 717b1dc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/output.js
Expand Up @@ -495,7 +495,7 @@ function webp (options) {
if (is.defined(options.smartSubsample)) {
this._setBooleanOption('webpSmartSubsample', options.smartSubsample);
}
const effort = options.effort || options.reductionEffort;
const effort = is.defined(options.effort) ? options.effort : options.reductionEffort;
if (is.defined(effort)) {
if (is.integer(effort) && is.inRange(effort, 0, 6)) {
this.options.webpEffort = effort;
Expand Down
6 changes: 6 additions & 0 deletions test/unit/webp.js
Expand Up @@ -133,6 +133,12 @@ describe('WebP', function () {
});
});

it('should set effort to 0', () => {
const effort = sharp().webp({ effort: 0 }).options.webpEffort;

assert.strictEqual(effort, 0);
});

it('invalid loop throws', () => {
assert.throws(() => {
sharp().webp({ loop: -1 });
Expand Down

0 comments on commit 717b1dc

Please sign in to comment.