if the resized and optimized image is larger than original, then keep the original

This commit is contained in:
zadam 2019-04-15 21:12:47 +02:00
parent 6b3c8b4bac
commit 8da8dfc543

View file

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