From e5ea8869cf699629227e91dee6bc122d897b0651 Mon Sep 17 00:00:00 2001 From: frankenbubble <62951241+frankenbubble@users.noreply.github.com> Date: Thu, 2 Sep 2021 17:08:14 +0100 Subject: [PATCH] make webp reduction effort a configurable allows you to set an environment variable WEBP_REDUCTION_EFFORT to configure the amount of effort that is put into webp reducing size. trade off is more cpu effort ($$$) vs file size --- source/image-handler/image-handler.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/source/image-handler/image-handler.js b/source/image-handler/image-handler.js index 62e1f6b17..b108fe4c3 100644 --- a/source/image-handler/image-handler.js +++ b/source/image-handler/image-handler.js @@ -33,6 +33,13 @@ class ImageHandler { } } + if (request.outputFormat === 'webp') { + const reductionEffortVal = process.env.WEBP_REDUCTION_EFFORT; + if (typeof reductionEffortVal !== "undefined") { + image = sharp(originalImage, { failOnError: false }).webp({reductionEffort: parseInt(reductionEffortVal, 10)}); + } + } + const modifiedImage = await this.applyEdits(image, edits); if (request.outputFormat !== undefined) { modifiedImage.toFormat(request.outputFormat);