aheckmann / gm

GraphicsMagick for node
http://aheckmann.github.com/gm/
6.96k stars 614 forks source link

dynamically append multiple images #380

Open Nedvedyy opened 9 years ago

Nedvedyy commented 9 years ago

Hi,

I have an array of images which I want to merge into 1. As the number of elements is not fixed, I am using

var paraArray = []; .... push the path of the images to the array. gm('./sprites/tn_1.png').append.apply(this,paraArray) gives the error

/Users/..../node_modules/gm/lib/args.js:64 this.addSrcFormatter(function (src) { ^ TypeError: Object # has no method 'addSrcFormatter' at append (/Users/..../node_modules/gm/lib/args.js:64:12)

If I call gm('./sprites/tn_1.png').append('./sprites/tn_2.png','./sprites/tn_3.png','./sprites/tn_4.png'), it works good. Any idea?

Regards Ned

rwky commented 9 years ago

That's because you're passing this which is out of context from gm. Try this

var img, paraArray = [], gm = require('gm');
/** push to array here **/
img = gm('./sprites/tn_1.png');
img.append.apply(img, paraArray);
/** continue to use img here to write/do whatever else you want **/