Files
Checkmate/Server/utils/imageProcessing.js
T

25 lines
502 B
JavaScript
Raw Normal View History

2024-10-15 11:57:37 +08:00
import sharp from "sharp";
/**
* Generates a 64 * 64 pixel image from a given image
* @param {} file
*/
const GenerateAvatarImage = async (file) => {
2024-10-17 12:07:30 +08:00
try {
// Resize to target 64 * 64
let resizedImageBuffer = await sharp(file.buffer)
.resize({
width: 64,
height: 64,
fit: "cover",
})
.toBuffer();
2024-10-17 12:07:30 +08:00
//Get b64 string
const base64Image = resizedImageBuffer.toString("base64");
return base64Image;
} catch (error) {
throw error;
}
};
2024-10-15 11:57:37 +08:00
export { GenerateAvatarImage };