How to add images in a loop with gm montage function?

1k views Asked by At

I want to combine several images in a grid. How can I accomplish the following without knowing the image paths beforehand?

gm('/path/to/image.jpg')
    .montage('/path/to/second_image.jpg')
    .montage('/path/to/third_image.jpg')
    .geometry('+100+150')
    .write('/path/to/montage.png', function(err) {
        if(!err) console.log("Written montage image.");
    });

Lets say the image pathes are available in an array:

paths=['/path/to/image.jpg', '/path/to/second_image.jpg', '/path/to/third_image.jpg');
1

There are 1 answers

1
AudioBubble On BEST ANSWER

hm. I did not use much that module, i d do,

var g = gm('/path/to/image.jpg');
paths.forEach(function(p){
    g.montage(p);
});
g.geometry('+100+150')
.write('/path/to/montage.png', function(err) {
    if(!err) console.log("Written montage image.");
});

no ?