如何使用Graphicsmagic创build缩略图?

我是node.js的新手,我试图玩GraphicsMagic。 我已经在我的Windows PC中安装了GraphicsMagic,并安装了与npm安装gm模块。 我能够得到全图像,但不能用下面的代码创build拇指。 任何人都可以帮助我走向正确的方向吗?

var express = require('express'); var app = express(); var fs = require('fs'); var gm = require('gm'); app.configure(function () { app.use(express.logger('dev')); app.use(express.bodyParser()); app.use(express.methodOverride()); }); app.listen(8080); console.log("App listening on port 8080"); app.post('/upload', function (req, res) { fs.readFile(req.files.image.path, function (err, data) { var imageName = req.files.image.name; if (!imageName) { console.log("There was an error"); res.redirect("/"); res.end(); } else { var newPath = __dirname + "/uploads/fullsize/" + imageName; var thumbPath = __dirname + "/uploads/thumbs/" + imageName; fs.writeFile(newPath, data, function (err) { gm(newPath) .resize(240, 240) .noProfile() .write(thumbPath, function (err) { if (!err) console.log('done'); res.redirect("/uploads/thumbs/"+imageName); }); }); } }); }); app.get('/uploads/thumbs/:file', function (req, res) { file = req.params.file; var img = fs.readFileSync(__dirname + "/uploads/thumbs/" + file); res.writeHead(200, {'Content-Type': 'image/jpg' }); res.end(img, 'binary'); }); app.get('*', function (req, res) { res.sendfile('./views/index.html'); // load the single view file (angular will handle the page changes on the front-end) }); 

index.html的:

 <!doctype html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <body> <form method="POST" action="/upload" enctype="multipart/form-data"> <input type="file" name="image" /> <input type="submit" name="submit" value="Submit"/> </form> </body> </html>