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;
问问题
457 次