title: GraphicsMagick: toBuffer() Stream yields empty buffer
body: <p>I am trying to read a file into a buffer, resize it and then write it to disk using the following example code:</p>
  
  <pre><code>function processImage(data) {
  gm(data, 'test.jpg')
      .resize('300x300')
    .background('white')
    .flatten()
    .setFormat('jpg')
    .toBuffer(function(err, buffer) {
      if (err) {
          throw err;
      } else {
          fs.writeFile('asd.jpg', buffer);
      }
    });
  }
  </code></pre>
  
  <p>However, this generates an error <code>Error: Stream yields empty buffer</code>. I have played around, used imageMagick and graphicsMagick, still the same. </p>
  
  <p>If i substitute<br>
  <code>toBuffer(...</code><br>
  with<br>
  <code>write('asd.jpg', function(err) ...</code></p>
  
  <p>it actually writes a proper file.</p>
  
  <p><strong>EDIT</strong> While writing this question I found the solution, see reply</p>