I am using imagemin
to minimize the image size.
After that, I find that the minimized image changed from portrait to landscape, which is unexpected for me.
Is there any way to prevent it from rotating?
...
async function minimizeImage(data){
var bufferFromImage = Buffer.from(data.image, 'base64');
if ((bufferFromImage.length / 1e+6) > 5) {
throw new errors.NotAcceptable("too large");
}
const miniBuffer = await minimizeImage(bufferFromImage);
}
const resize = async (input) => {
return sharp(input)
.resize(250)
.toBuffer();
};
const minimizeImage = async (bufferFromImage) => {
if ((bufferFromImage.length / 1e+6) > 0.1) {
return await imagemin.buffer(bufferFromImage, {
plugins: [resize]
});
} else {
return bufferFromImage;
}
}
Finally solved it by using jpeg-autorotate
library.
There is a post related to this problem.
Wrong Image orientation when uploading - Amazon S3