fix importing unknown image types such as .DWG, closes #2628

This commit is contained in:
zadam 2022-02-11 22:01:45 +01:00
parent 40598d2663
commit 59e8720866

View file

@ -17,8 +17,7 @@ async function processImage(uploadBuffer, originalName, shrinkImageSwitch) {
const compressImages = optionService.getOptionBool("compressImages");
const origImageFormat = getImageType(uploadBuffer);
if (origImageFormat && ["webp", "svg", "gif"].includes(origImageFormat.ext)) {
// JIMP does not support webp at the moment: https://github.com/oliver-moran/jimp/issues/144
if (!origImageFormat || !["jpg", "png"].includes(origImageFormat.ext)) {
shrinkImageSwitch = false;
}
else if (isAnimated(uploadBuffer)) {
@ -26,9 +25,18 @@ async function processImage(uploadBuffer, originalName, shrinkImageSwitch) {
shrinkImageSwitch = false;
}
const finalImageBuffer = (compressImages && shrinkImageSwitch) ? await shrinkImage(uploadBuffer, originalName) : uploadBuffer;
let finalImageBuffer;
let imageFormat;
const imageFormat = getImageType(finalImageBuffer);
if (compressImages && shrinkImageSwitch) {
finalImageBuffer = await shrinkImage(uploadBuffer, originalName);
imageFormat = getImageType(finalImageBuffer);
} else {
finalImageBuffer = uploadBuffer;
imageFormat = origImageFormat || {
ext: 'dat'
};
}
return {
buffer: finalImageBuffer,
@ -43,7 +51,9 @@ function getImageType(buffer) {
}
}
else {
return imageType(buffer) || "jpg"; // optimistic JPG default
return imageType(buffer) || {
ext: "jpg"
}; // optimistic JPG default
}
}