0

I am generating a PNG on the server side of a node.js application, using ImageMagick and the gm library for node.js (GraphicsMagick for node.js).

// start with a blank image
var gmImage = gm(100, 100, "#000000ff");

// Draw the stuff on the new blank image

When I'm finished drawing stuff using the gm library, I am storing that image to the file system:

gmImage.write(imagePath, function (err) {
  ...
});

I am now moving to s3. I want to skip this previous step and write the image direct to s3 without using a temporary file.

Is there a way to write the gmImage to a buffer or something?

JT703
  • 1,311
  • 4
  • 17
  • 41

1 Answers1

0

Take a look at the stream section of the API: https://github.com/aheckmann/gm#streams

You should be able to pipe stdout into s3

var gmImage = gm(100, 100, "#000000ff");
gmImage.stream(function (err, stdout, stderr) {
  stdout.pipe(s3Stream);
});
generalhenry
  • 17,227
  • 4
  • 48
  • 63
  • how do you create that `s3Stream`? `fs.createWriteStream("[s3url]");` ? I don't know why I can't find an example of creating a write stream to s3. – JT703 Apr 16 '13 at 13:47
  • Using knox, https://github.com/LearnBoost/knox you can use a putStream. `client.putStream(stdout, '/image.png', function (err, res) { . . . });` – generalhenry Apr 16 '13 at 16:11