在 Node.js (AWS Lamda) 中使用 Jimp 将 .jpg 图像转换为 png
我正在编写一个 AWS Node.js Lambda 函数(使用无服务器)来在给定初始 URL 的情况下转换不同格式的图像(即 JPG--> PNG)。我正在使用 Jimp 库,根据文档,该库使用以下代码实现此功能:
Jimp.read(JPG_URL, function (err, image) {
if (err) {
console.log(err)
} else {
image.write("new-image.png")
}
})
现在,在我正在使用的 Lambda 函数中:
let img_data = await Jimp.read(JPG_URL);
效果很好,实际上我可以使用 img_data
来执行不同的转换(即img_data.greyscale()
)。问题是(据我所知)Lambda 的文件系统是只读的,而 Jimp 似乎不支持直接转换为变量的方法。
如何在不依赖文件系统的情况下执行转换?
I'm writing an AWS Node.js Lambda function (using Serverless) to convert images across different formats (i.e. JPG--> PNG) given an initial URL. I'm using the Jimp library which, according to the documentation, implements this functionality with the code:
Jimp.read(JPG_URL, function (err, image) {
if (err) {
console.log(err)
} else {
image.write("new-image.png")
}
})
now, in my Lambda function I'm using:
let img_data = await Jimp.read(JPG_URL);
which works well, indeed I can use img_data
to perform different transformations (i.e. img_data.greyscale()
). The problem is that (AFAIK) Lambda's filesystem is read-only and Jimp doesn't seem to support a way to convert directly to a variable.
How can I perform the conversion without relying on the filesystem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试锐利,如下所示
You may try sharp like below