1
0
Fork 0
mirror of synced 2024-09-27 23:01:51 +12:00
budibase/packages/server/src/utilities/fileSystem/processor.js

22 lines
453 B
JavaScript
Raw Normal View History

const jimp = require("jimp")
2020-09-17 23:45:28 +12:00
const FORMATS = {
IMAGES: ["png", "jpg", "jpeg", "gif", "bmp", "tiff"],
2020-09-17 23:45:28 +12:00
}
function processImage(file) {
// this will overwrite the temp file
return jimp.read(file.path).then(img => {
return img.resize(300, jimp.AUTO).write(file.path)
})
2020-09-17 23:45:28 +12:00
}
2020-09-18 22:01:39 +12:00
async function process(file) {
2020-09-17 23:45:28 +12:00
if (FORMATS.IMAGES.includes(file.extension.toLowerCase())) {
await processImage(file)
2020-09-17 23:45:28 +12:00
}
2020-09-18 22:01:39 +12:00
return file
2020-09-17 23:45:28 +12:00
}
2020-09-18 03:36:39 +12:00
exports.process = process