Generate avatar image on register or update if an image is included

This commit is contained in:
Alex Holliday committed 2024-07-08 10:26:56 -07:00
1 parent f9ca58c00a
commit 43bac259d7
6 files changed
+594 -22

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
const sharp = require("sharp");
/**
* Generates a 64 * 64 pixel image from a given image
* @param {} file
*/
const GenerateAvatarImage = async (file) => {
try {
// Resize to target 64 * 64
let resizedImageBuffer = await sharp(file.buffer)
.resize({
width: 64,
height: 64,
fit: "cover",
})
.toBuffer();
//Get b64 string
const base64Image = resizedImageBuffer.toString("base64");
return base64Image;
} catch (error) {
throw error;
}
};
module.exports = {
GenerateAvatarImage,
};