I have an aws image file and Iam compressing the image using sharp , but after compressing, the file size is increasing hugely . In my case I have an image size of 6.5MB , which after compressing it is becoming 19.5MB.
The following is my code :
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) => {
........
........
}
I have even tried using .max()
,
sharp(data.Body)
.withoutEnlargement()
.resize(width, height)
.toFormat('png')
.toBuffer()
The same issue , file size is increasing . In my case the image aspect ratio should be maintained. Any suggestions would be appreciated. Thanks