简体   繁体   English

如何在amazon lambda函数中使用node.js进行图像叠加和水印

[英]How to do image overlay and watermark using node.js in amazon lambda function

I have images hosted on amazons3 server.my client wants to process the images using amazon lambda function.我在 amazons3 服务器上托管了图像。我的客户端想要使用 amazon lambda 函数处理图像。 I have followed the example: http://docs.aws.amazon.com/lambda/latest/dg/walkthrough-s3-events-adminuser-create-test-function-create-function.html我遵循了这个例子: http : //docs.aws.amazon.com/lambda/latest/dg/walkthrough-s3-events-adminuser-create-test-function-create-function.html

It is fine for resizing.调整大小很好。 But I want overlay and watermarking for the images also.But not getting a way.I have tried with imagemagick[ https://www.npmjs.com/package/gm] for it seems to take path as parameter and the s3 image path is not helping me.但我也想要图像的叠加和水印。但没有找到方法。我尝试过使用 imagemagick[ https://www.npmjs.com/package/gm]因为它似乎将路径作为参数和 s3 图像路径没有帮助我。 the obvious reason I think is that they can't be directly accessed as the images paths in the directory.我认为最明显的原因是它们不能作为目录中的图像路径直接访问。

Any suggestion on how to achieve this.关于如何实现这一目标的任何建议。 I stuck for last 3 days but not able move forward.Thanks in advance for help!!!!我坚持了最后 3 天,但无法继续前进。提前感谢您的帮助!!!!

It looks like your are trying to do the overlaying in the size action.看起来您正在尝试在 size 操作中进行覆盖。 A quick check over at the gm repository on GitHub showed an issue with a possible solution .快速检查GitHub 上gm 存储库显示了一个可能的解决方案问题 It seems as thought the composite action accepts a stream to read from.似乎认为复合动作接受要读取的流。 In regards to your code I would suggest a refactor to chain the actions together.关于您的代码,我建议进行重构以将操作链接在一起。 I'm not sure I understand where the write stream is going in your original function though.我不确定我是否理解写入流在原始函数中的去向。 Let me know if this helps!让我知道这是否有帮助!

var scalingFactor = Math.min(
  newSize / size.width,
  newSize / size.height
);

var width  = scalingFactor * size.width;
var height = scalingFactor * size.height;

gm(response.Body)
.autoOrient()
.resize(width, height)
.gravity('SouthEast')
.draw('image Over 0,0 0,0 ' + getAppPath() + '/path/to/wm-bas.png')
.stream('PNG') // This converts the whole thing to a png, not sure if you want this
.pipe(writeStream) // Change this

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

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