我正在尝试使用ImageMagick来调整图片大小,我已经提到了this example
我收到此错误:
{ [Error: Command failed: Invalid Parameter - -set
] timedOut: false, killed: false, code: 4, signal: null }
以下是我的代码:
exports.generateThumbnail=function(imageURL,savePath,filename,callback){
console.log(imageURL);
console.log(savePath);
console.log(filename);
var options = {
width: 80,
height: 80,
srcPath: imageURL,
dstPath: savePath+"\\thumb_"+filename
};
im.resize(options, function(err) {
if(err) { console.log( err); }
console.log("Image resize complete");
});
}
这是我在控制台中获得的所有内容:
fieldNameHere
{ _readableState:
{ highWaterMark: 16384,
buffer: [],
length: 0,
pipes: null,
pipesCount: 0,
flowing: false,
ended: false,
endEmitted: false,
reading: false,
calledRead: false,
sync: true,
needReadable: false,
emittedReadable: false,
readableListening: false,
objectMode: false,
defaultEncoding: 'utf8',
ranOut: false,
awaitDrain: 0,
readingMore: false,
decoder: null,
encoding: null },
readable: true,
domain: null,
_events: { end: [Function] },
_maxListeners: 10,
truncated: false,
_read: [Function] }
look.png
7bit
image/png
.\Images\bhuwan\media\look.pnglook.png
.\Images\bhuwan\media
look.png
{ [Error: Command failed: Invalid Parameter - -set
] timedOut: false, killed: false, code: 4, signal: null }
此外,我已经尝试过npmjs.org上的每个可能的库,包括最流行的像easyimage和node-thumbnail。他们都没有在Windows上工作,并且在github上列出了问题。
我在这方面做错了什么?请帮忙。!
修改
以防你需要我调用上述方法的代码:
app.post('/uploadImage',function(req,res){
console.log('Starting to read params');
var alias=req.query.alias;
var imagetype=req.query.imagetype; //can be media/profile
console.log(alias);
console.log(imagetype);
var busboy = new Busboy({ headers: req.headers });
busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
saveTo = ".\\Images\\"+alias+"\\"+imagetype+"\\"+filename;
saveDirectory= ".\\Images\\"+alias+"\\"+imagetype;
console.log(fieldname);
console.log(file);
console.log(filename); //this is the one
ImageName=filename;
console.log(encoding);
console.log(mimetype);
imagePathFull=saveTo+filename;
if (fs.existsSync(saveTo)) {
file.pipe(fs.createWriteStream(saveTo));
}
else{
mkdirp(".\\Images\\"+alias+"\\"+imagetype,function(err){
file.pipe(fs.createWriteStream(saveTo));
});
}
});
busboy.on('finish', function() {
imageHandle.generateThumbnail(imagePathFull,saveDirectory,ImageName,function(err){
if(!err){
res.writeHead(200, { 'Connection': 'close' });
res.status(200).end();
}
else{
res.writeHead(500, { 'Connection': 'close' });
res.status(500).end();
}
});
});
return req.pipe(busboy);
});
答案 0 :(得分:1)
我遇到了同样的问题,并按照此处的建议imagemagick with nodejs not working在Windows上安装imagemagik.exe
解决了这个问题。
下载:http://www.imagemagick.org/script/binary-releases.php#windows
希望它有所帮助!