【发布时间】:2016-06-27 19:38:48
【问题描述】:
我正在使用这个节点包:
https://www.npmjs.com/package/sharp
我使用它来调整图像大小,然后将其上传到亚马逊 S3。
可以找到大多数图像,但其中一些(我假设基于纵横比)会被旋转。
有没有办法防止这种情况或原因?
这是我正在使用的代码的副本。 imageData 是从文件上传的 s3 存储桶文件中获取的数据。 如您所见,我没有调用旋转函数。无论如何要“锁定”旋转?
module.exports.resize = function(imageData, width, fileName){
sharp(imageData).resize(parseInt(width), null).toBuffer(function (err, data) {
if (err) throw err;
s3.putObject({
Bucket: aws.bucket,
Key: 'images/' + width + '/' + fileName,
Body: data
}, function (err, data) {
if (err) {
console.log('Failed to resize image due to an error: ' + err);
return {
message: 'Failed to resize image due to an error: ' + err
};
} else {
console.log('s3 image uploaded to ' + 'images/' + width + '/' + fileName);
return {
message: 's3 image uploaded to ' + 'images/' + width + '/' + fileName
};
}
});
});
});
【问题讨论】:
-
如果你能显示你的代码和测试图像会更好。
-
您的图像是否可能包含您的查看器或 libvips(sharp 的支持库)未考虑的 EXIF 方向数据?
-
如何检查 EXIF 方向数据?
-
您好,这里是锐利的维护者。 @mikefrey 的评论是最有可能的解释。默认情况下,Sharp 删除 EXIF 元数据。将
rotate()添加到您的处理链中,以便在删除图像之前根据 EXIF 元数据自动旋转图像。
标签: node.js amazon-s3 image-resizing image-rotation