Improve image compression (#2369)

* added options

* added checkbox handling to import into note

* added image compression option respecting
This commit is contained in:
Myzel394
2021-11-21 15:27:13 +00:00
committed by GitHub
parent de20183a22
commit 886fdf7cd6
6 changed files with 54 additions and 11 deletions

View File

@@ -14,6 +14,7 @@ const isSvg = require('is-svg');
const isAnimated = require('is-animated');
async function processImage(uploadBuffer, originalName, shrinkImageSwitch) {
const compressImages = optionService.getOptionBool("compressImages");
const origImageFormat = getImageType(uploadBuffer);
if (origImageFormat && ["webp", "svg", "gif"].includes(origImageFormat.ext)) {
@@ -25,7 +26,7 @@ async function processImage(uploadBuffer, originalName, shrinkImageSwitch) {
shrinkImageSwitch = false;
}
const finalImageBuffer = shrinkImageSwitch ? await shrinkImage(uploadBuffer, originalName) : uploadBuffer;
const finalImageBuffer = (compressImages && shrinkImageSwitch) ? await shrinkImage(uploadBuffer, originalName) : uploadBuffer;
const imageFormat = getImageType(finalImageBuffer);