2

我正在编写一个图像大小调整 lambda 函数。它从 s3 读取一个对象并用于jimp调整它的大小。当我运行它时,我得到这个错误:

ERROR   (node:9) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.

我已经将其追溯到jimpin image.scaleToFit()。在本地运行时我没有收到此错误。两者都在运行节点 14。我假设这是 AWS Lambda 特有的。

我失败的代码:

    const { Body } = s3Result;  //body is a buffer
    const jimpImage = await Jimp.read(Body).then((image) => {
      
      // debug tells me the bug happens here
      let imageResult = image.scaleToFit(width, height)

      imageResult = imageResult.quality(
        quality
      );
      return imageResult.getBufferAsync("image/jpg");
    });

是否有解决此问题的方法,以便我可以继续使用jimp

欢迎在评论中提出替代方案。

谢谢

4

0 回答 0