Browse Source

fixed croup

unknown 2 years ago
parent
commit
e22f2f5ec4
1 changed files with 10 additions and 0 deletions
  1. 10 0
      controllers/user.js

+ 10 - 0
controllers/user.js

@@ -3,6 +3,7 @@ const ChatModel = require('../model/chat');
 const MessageModel = require('../model/message');
 const ContactModel = require('../model/contact');
 const fs = require('fs').promises;
+const Jimp = require('jimp');
 const path = require('path');
 const jwt = require('jsonwebtoken');
 const createFolderIsExist = require('../helpers/create-directory');
@@ -205,6 +206,15 @@ const updateAvatar = async (req, res, next) => {
 		const originalName = req.file.originalname;
 		const newNameAvatar = `${Math.round(Date.now() / 1000)}${originalName}`;
 		await createFolderIsExist(path.join(DIR_STATIC, userId));
+		const img = await Jimp.read(pathToFile);
+		await img
+			.autocrop()
+			.cover(
+				250,
+				250,
+				Jimp.HORIZONTAL_ALIGN_CENTER | Jimp.VERTICAL_ALIGN_MIDDLE
+			)
+			.writeAsync(pathToFile);
 		await fs.rename(pathToFile, path.join(DIR_STATIC, userId, newNameAvatar));
 		const avatarUrl = path.normalize(path.join(userId, newNameAvatar));
 		const avatarsArr = [