Skip to content

Commit 65a92e8

Browse files
committed
Separate module created for image resize
1 parent b34830c commit 65a92e8

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

controller/image.controller.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const Jimp=require('jimp')
2+
3+
module.exports={
4+
ppResize:function(img,height,width){
5+
imgDir="./views/uploads/profilePics/"+img
6+
console.log(typeof(imgDir))
7+
Jimp.read(imgDir, (err, img) => {
8+
if (err) throw err;
9+
img
10+
.resize(width,height)
11+
.quality(60)
12+
.write(imgDir)
13+
});
14+
}
15+
}

routes/login.routes.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const route = express.Router();
77
const multer=require('multer')
88
const path=require('path')
99
const Jimp=require('jimp')
10+
const imagecontroller=require('../controller/image.controller')
1011

1112
//MULTER
1213
const storage=multer.diskStorage({
@@ -21,17 +22,7 @@ const upload=multer({
2122
storage:storage
2223
});
2324

24-
ppResize=function(img,height,width){
25-
imgDir="./views/uploads/profilePics/"+img
26-
console.log(typeof(imgDir))
27-
Jimp.read(imgDir, (err, img) => {
28-
if (err) throw err;
29-
img
30-
.resize(width,height)
31-
.quality(60)
32-
.write(imgDir)
33-
});
34-
}
25+
3526
//get request
3627

3728
route.get('/google', passport.authenticate('google', { scope: ['profile'] }));
@@ -93,7 +84,7 @@ route.post('/userlogin',upload.single('profilepic'), function(req, res) {
9384
res.send("ERROR")
9485
})
9586
.then(function(use) {
96-
ppResize(img,300,300)
87+
imagecontroller.ppResize(img,300,300)
9788
res.send(use)
9889
});
9990
});
7.78 KB
Loading

0 commit comments

Comments
 (0)