0

我正在尝试将多个图像合成到一个流中,该流将作为响应进行管道传输。我在https://github.com/aheckmann/gm使用 Node.js 和 GraphicsMagick for Node 。

如果我将两个图像合成到一个流中,它可以正常工作,对于这个例子,它显示了预期的最终合成的二/三。这是我的代码:

app.get('/call_2image_stream', function(req, res){

    res.writeHead(200, {'Content-Type' : 'image/png'});
    var path = (__dirname + '/test_folder/happy_right.png');
    var path2 = (__dirname + '/test_folder/happy_left.png');
    gm(path)
      .composite(path2)
      .stream('png')
      .pipe(res);
})

这在邮递员中效果很好 祝你有美好的一天

但是当我尝试合成三张图像时,它并没有按预期正确地填充图片的底部。代码是这样的:

app.get('/call_3image_stream', function(req, res){

    res.writeHead(200, {'Content-Type' : 'image/png'});
    var path = (__dirname + '/test_folder/happy_bottom.png');
    var path2 = (__dirname + '/test_folder/happy_right.png');
    var path3 = (__dirname + '/test_folder/happy_left.png');
    gm(path)
      .composite(path2)
      .composite(path3)
      .stream('png')
      .pipe(res);
})

我无法弄清楚为什么输出是这样的: 不再有最好的一天

4

1 回答 1

0

想出一个很好的答案写在这里:https: //stackoverflow.com/a/20611669/4447761 向 Ryan Wu 大喊!

这是我的最终代码

app.get('/final_code', function(req, res){
    res.writeHead(200, {'Content-Type' : 'image/png'});
    gm()
     .in('-page', '+0+0')
     .in(__dirname + '/test_folder/happy_right.png')
     .in('-page', '+0+0') 
     .in(__dirname + '/test_folder/happy_left.png')
     .in('-page', '+0+0') 
     .in(__dirname + '/test_folder/happy_bottom.png')
     .mosaic()
     .stream('png')
     .pipe(res);
})

作品!

于 2015-09-26T06:02:07.770 回答