Skip to content

Commit

Permalink
fix importing unknown image types such as .DWG, closes #2628
Browse files Browse the repository at this point in the history
  • Loading branch information
zadam committed Feb 11, 2022
1 parent 40598d2 commit 59e8720
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/services/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,26 @@ 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)) {
// recompression of animated images will make them static
shrinkImageSwitch = false;
}

const finalImageBuffer = (compressImages && shrinkImageSwitch) ? await shrinkImage(uploadBuffer, originalName) : uploadBuffer;

const imageFormat = getImageType(finalImageBuffer);
let finalImageBuffer;
let imageFormat;

if (compressImages && shrinkImageSwitch) {
finalImageBuffer = await shrinkImage(uploadBuffer, originalName);
imageFormat = getImageType(finalImageBuffer);
} else {
finalImageBuffer = uploadBuffer;
imageFormat = origImageFormat || {
ext: 'dat'
};
}

return {
buffer: finalImageBuffer,
Expand All @@ -43,7 +51,9 @@ function getImageType(buffer) {
}
}
else {
return imageType(buffer) || "jpg"; // optimistic JPG default
return imageType(buffer) || {
ext: "jpg"
}; // optimistic JPG default
}
}

Expand Down

0 comments on commit 59e8720

Please sign in to comment.