简体   繁体   English

使用 gm imagemagick 调整大小、裁剪和单色获取超时的 AWS 节点 js lambda

[英]AWS node js lambda using gm imagemagick resize, crop and monochrome getting timeout

My lambda function watches s3, gets object and crops/resizes to desired sizes, then uploads.我的 lambda 函数监视 s3,获取对象并裁剪/调整到所需的大小,然后上传。 I do have the lambda layer for imagemagick, and I've had some success with resize, but it works maybe 10% of the time.我确实有用于 imagemagick 的 lambda 层,并且我在调整大小方面取得了一些成功,但它可能有 10% 的时间有效。 These are my imagemagick functions,这些是我的 imagemagick 函数,

exports.resizeImg = async (buf, width, height) => {
  return new Promise((resolve, reject) => {
    gm(buf).resize(width, height).noProfile().toBuffer((err, buffer) => err ? console.log(err) : resolve(buffer));
   });
};

exports.cropImg = async (buf, width, height) => {
  return new Promise((resolve, reject) => {
    gm(buf).crop(width, height, 0, 0).noProfile().toBuffer((err, buffer) => err ? reject(err) : resolve(buffer));
   });
};

exports.monochromeImg = async (buf) => {
  return new Promise((resolve, reject) => {
    gm(buf).monochrome().noProfile().toBuffer((err, buffer) => err ? reject(err) : resolve(buffer));
   });
};

calling the resize or crop as调用调整大小或裁剪为

const resized = await resizeImg(buffer, 200, 200);

then passing the binary/buffer to s3 upload, which is working.然后将二进制/缓冲区传递给 s3 上传,这是有效的。 If resize works.如果调整大小有效。

I've also tried to write the buffer to fs, but no luck there either.我也尝试将缓冲区写入 fs,但也没有运气。

 exports.resizeImage = async (buf, width, height, path) => {
     gm(buf)
     .resize(width, height, "!")
     .write(path + 'output/1111.jpg', function(err){
     if (err) return console.dir(arguments)
     console.log(this.outname + " created  ::  " + arguments[3])
      })
  }

Does imagemagick still work? imagemagick 仍然有效吗? Or should I just use sharp?还是我应该只使用锐利?

i have same error i fix with incress the timeout time我有同样的错误,我通过增加超时时间来修复

new aws UI新的 aws 用户界面

lambda function -> configuration -> General configuration -> Edit Timeout

在此处输入图片说明

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

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