From 4662527a1755f932952d2465c36a91fb56da7e6b Mon Sep 17 00:00:00 2001 From: AlexanderTheGrey <67391446+AlexanderTheGrey@users.noreply.github.com> Date: Fri, 17 Jun 2022 02:22:51 -0500 Subject: [PATCH] Allow WebP encoding effort of 0 (#3261) --- lib/output.js | 2 +- test/unit/webp.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/output.js b/lib/output.js index ef2b01b5f..8866b1e1b 100644 --- a/lib/output.js +++ b/lib/output.js @@ -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; diff --git a/test/unit/webp.js b/test/unit/webp.js index a9b818f85..260ba0a50 100644 --- a/test/unit/webp.js +++ b/test/unit/webp.js @@ -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 });