我目前正在使用angular-file-upload指令,而且我几乎使用了演示中的确切代码.
我需要在那里添加一个步骤来测试图像的尺寸,我目前只能通过jQuery/javascript来做.
只是想知道在上传之前是否有一种"有角度"的方式来检查图像的尺寸?
$scope.uploadImage = function($files) {
$scope.selectedFiles = [];
$scope.progress = [];
if ($scope.upload && $scope.upload.length > 0) {
for (var i = 0; i < $scope.upload.length; i++) {
if ($scope.upload[i] !== null) {
$scope.upload[i].abort();
}
}
}
$scope.upload = [];
$scope.uploadResult = [];
$scope.selectedFiles = $files;
$scope.dataUrls = [];
for ( var j = 0; j < $files.length; j++) {
var $file = $files[j];
if (/*$scope.fileReaderSupported && */$file.type.indexOf('image') > -1) {
var fileReader = new FileReader();
fileReader.readAsDataURL($files[j]);
var loadFile = function(fileReader, index) {
fileReader.onload = function(e) {
$timeout(function() {
$scope.dataUrls[index] = e.target.result;
//------Suggestions?-------//
$('#image-upload-landscape').on('load', function(){
console.log($(this).width());
});
//-------------------------//
});
};
}(fileReader, j);
}
$scope.progress[j] = -1;
if ($scope.uploadRightAway) {
$scope.start(j);
}
}
};
Run Code Online (Sandbox Code Playgroud)
我想你可以做到:
var reader = new FileReader();
reader.onload = onLoadFile;
reader.readAsDataURL(filtItem._file);
function onLoadFile(event) {
var img = new Image();
img.src = event.target.result;
console.log(img.width, img.height)
}
Run Code Online (Sandbox Code Playgroud)
这是从https://github.com/nervgh/angular-file-upload/blob/master/examples/image-preview/directives.js复制的代码段.
我认为这更像是angularjs.但是,您可能需要对其进行修改以满足您的要求.
| 归档时间: |
|
| 查看次数: |
7904 次 |
| 最近记录: |