Domanda

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?

È stato utile?

Soluzione

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);
});
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top