简体   繁体   English

将生成的ImageMagick图像存储到不带临时文件的s3中

[英]Store generated ImageMagick image to s3 without temp files

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 ). 我正在使用ImageMagick和用于node.js的gm库(用于node.js的GraphicsMagick )在node.js应用程序的服务器端生成PNG。

// 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: 当我完成了使用gm库的绘图工作后,便将该图像存储到文件系统中:

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

I am now moving to s3. 我现在要移至s3。 I want to skip this previous step and write the image direct to s3 without using a temporary file. 我想跳过上一步,而不使用临时文件将图像直接写入s3。

Is there a way to write the gmImage to a buffer or something? 有没有一种方法可以将gmImage写入缓冲区或其他内容?

Take a look at the stream section of the API: https://github.com/aheckmann/gm#streams 看一下API的流部分: https : //github.com/aheckmann/gm#streams

You should be able to pipe stdout into s3 您应该能够将stdout传送到s3

var gmImage = gm(100, 100, "#000000ff");
gmImage.stream(function (err, stdout, stderr) {
  stdout.pipe(s3Stream);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM