Allow WebP encoding effort of 0 (#3261)

This commit is contained in:
AlexanderTheGrey 2022-06-17 02:22:51 -05:00 committed by GitHub
parent b10d8f89ca
commit 4662527a17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -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;

View File

@ -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 });