【发布时间】:2019-01-03 16:22:56
【问题描述】:
我有一个 aws 图像文件,我正在使用 sharp 压缩图像,但压缩后,文件大小急剧增加。就我而言,我的图像大小为 6.5MB ,压缩后变为 19.5MB。
以下是我的代码:
const width = parseInt(image.height);
const height = parseInt(image.width);
var getObjectParams = {
Bucket: BUCKET,
Key: FILE_NAME
}
s3.getObject(getObjectParams).promise()
.then(data => {
sharp(data.Body)
.resize(width, height)
.ignoreAspectRatio()
.toFormat('png')
.toBuffer()
.then((buffer) => {
........
........
}
我什至尝试过使用.max(),
sharp(data.Body)
.withoutEnlargement()
.resize(width, height)
.toFormat('png')
.toBuffer()
同样的问题,文件大小在增加。在我的情况下,应该保持图像纵横比。任何建议,将不胜感激。谢谢
【问题讨论】:
-
你已经在github.com/lovell/sharp/issues 上问过这个问题了吗?如果没有,请这样做,因为作为一个开源库,这确实是第一个要问的地方。
-
@Mike'Pomax'Kamermans 是的,我在 github 上问过 github.com/lovell/sharp/issues/1307
-
好。看起来你会想在那里编辑你的问题,github有不同的代码格式格式(SO使用缩进,GH在你的代码块之前和之后使用```)
-
@Mike'Pomax'Kamermans,谢谢你的建议,我会调查一下