javascript - 无法使用 ImageMagick Node.js 调整图像大小

标签 javascript node.js imagemagick

我正在尝试使用 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);
});

最佳答案

我遇到了同样的问题,并按照此处的建议在 Windows 上安装 imagemagik.exe 解决了该问题:imagemagick with nodejs not working .

下载:Link

希望对你有帮助!

关于javascript - 无法使用 ImageMagick Node.js 调整图像大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26130914/

相关文章:

javascript - 我怎样才能在 react 中停止我的列表的这种奇怪的输出

javascript - node.js 的 raw_input 替代方案

ImageMagick 错误 : Convert PDF to Images

linux - imagemagick 自动编号从 1 开始

javascript - 将 appBar 按钮的标签放在图标图像旁边而不是图标图像下方

javascript - 不断读取本地文本文件

javascript - 通过 Node 服务器上的 gzip 压缩提高 React 应用程序的 Google 页面速度分数?

javascript - 使用 moment.js 防止 DST 偏移以处理重复发生的事件

node.js - 将 ember.js 与 node.js + express.js 结合使用

php - 如何确定我是否安装了 gd 库或 imagemagick?