const express = require('express');
const multer = require('multer');
var fs = require('fs')
, gm = require('gm').subClass({imageMagick: true});
const router = express.Router();
const storage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, './public/images')
},
filename: (req, file, cb) => {
cb(null, file.originalname + '-' + Date.now() + '.png')
}
})
var upload = multer({ storage: storage }).single('image');
router.get('/', (req, res, next) => {
res.render('index', {
title: 'Express'
})
});
router.post('/', upload, (req, res, next) => {
gm(req.file.path)
.resize(240, 240)
.gravity('Center')
.extent(240, 240)
.noProfile()
.write('./public/images/update/' + req.file.originalname + '-' + Date.now(), function(err){
console.log('err', err);
})
})
module.exports = router;
Asked
Active
Viewed 860 times
0

Arkar Aung
- 3,554
- 1
- 16
- 25

ahmed fouad
- 11
- 3
-
are you sure about the syntax you're using? cause docs https://www.npmjs.com/package/imagemagick shows otherwise. – Aniket Kariya Jul 18 '20 at 06:35
-
i'm here using just multer and gm to resize an image and in using gm i have to install GraphicsMagick or ImageMagick [npmjs.com/package/gm](https://www.npmjs.com/package/gm) and i installed imagemagick but the error is still appearing – ahmed fouad Jul 18 '20 at 10:22
-
Are you using windows? from a little bit of research, it seems that the problem is convert.exe. Try placing your ImageMagick path variable before the system32 variable in your environment variables. – Aniket Kariya Jul 18 '20 at 11:17
-
instead of messing path variables, I would suggest you use sharp package. It does not have any external dependency. https://www.npmjs.com/package/sharp. It's just a suggestion unless you must have to use gm for some reason. – Aniket Kariya Jul 18 '20 at 11:23