我正在使用“react-dropzone”为用户提供上传图像的方法。当用户提交时,我将图像保存在亚马逊 S3 云中。我需要测量图像宽度,但我已经尝试过 imagemagick 包和其他一些 npm 模块,但我总是遇到一些问题,例如“找不到模块“fs””或“找不到模块“../lib/detector”(…) ”。有什么建议吗?
S3.upload({
files:this.files,
path:"tours/"+this.tourId
},function(e,result){
// Get Image width here
});
最佳答案
每个文件
都应该有一个.preview
属性(除非您设置disablePreview
属性)。 file.preview
是一个 blob URL,您可以将其加载到 Image()
中以捕获其 onload
事件中的宽度和高度:
var image = new Image();
image.src = window.URL.createObjectURL(file.preview);
image.onload = function () {
var width = image.width;
var height = image.height;
// TODO: Do something with the dimensions
};
关于javascript - MeteorJS 获取图像宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40981253/