title: Generate Animated GIF with GM in Node.js
body: <p>so i've been tackling this one for a few days and got the point when i'm ready to ask for help.</p>
  
  <p>I'm trying to generate an animated gif with in a node.js based app, using the <a href="http://aheckmann.github.io/gm/docs.html#imagemagick" rel="noreferrer">graphicsmagic</a> package.</p>
  
  <p>I've generated several slides that look kinda like that</p>
  
  <pre><code>var slides = [];
  
  for (var i=0; i &lt; 10; i++) {
    var slide = gm(200, 200, '#000000')
      .fill('#ffffff')
      .drawText("Slide #"+ i);
  
    slides.push(slide);
  }
  </code></pre>
  
  <p>I can convert them either into streams or buffers, i can save them as individual files on the hard drive and kinda works</p>
  
  <p>But my problem is how to make an animated gif from those slides completely <em>in memory, without</em> saving the individual files on a hard drive?</p>
  
  <p>I see <code>gm</code> has methods like <code>#delay()</code> and <code>#page()</code> and so technically i could craft a command like</p>
  
  <pre><code>convert -delay 200 -page slide1.gif -page slide2.gif output.gif
  </code></pre>
  
  <p>I just don't know how. I'm thinking it should looks something like that</p>
  
  <pre><code>var end_image = gm(200, 200, '#000000');
  
  end_image.delay(500);
  
  for (var i=0; i &lt; slides.length; i++) {
    slides[i].toBuffer(function(err, buffer) {
      end_image.page(200, 200, ????);
    });
  }
  
  end_image.write("output.gif");
  </code></pre>
  
  <p>basically I don't know how to convert a buffer into an argument for <code>gm</code> </p>
  
  <p>Have anyone done it before? Maybe there is another way?</p>
  
  <p>PS: i tried to use the <code>gifencoder</code> package as well, and successfully fed the <code>gm</code> buffers as frames into a gifencoder's API, but the output was all broken.</p>