From 8da8dfc5433a87e03d86cae8b636b18973d7b8bf Mon Sep 17 00:00:00 2001 From: zadam Date: Mon, 15 Apr 2019 21:12:47 +0200 Subject: [PATCH] if the resized and optimized image is larger than original, then keep the original --- src/services/image.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/services/image.js b/src/services/image.js index f65f498b4..90e34139c 100644 --- a/src/services/image.js +++ b/src/services/image.js @@ -51,6 +51,13 @@ async function shrinkImage(buffer, originalName) { log.error("Failed to optimize image '" + originalName + "\nStack: " + e.stack); finalImageBuffer = resizedImage; } + + // if resizing & shrinking did not help with size then save the original + // (can happen when e.g. resizing PNG into JPEG) + if (finalImageBuffer.byteLength >= buffer.byteLength) { + finalImageBuffer = buffer; + } + return finalImageBuffer; }