Html 如何在AngularJS中获取图像尺寸?

Html 如何在AngularJS中获取图像尺寸?,html,angularjs,Html,Angularjs,我想在用户选择要上载的文件时检查图像的尺寸 到目前为止,我已经完成了以下代码: HTML <input type="file" accept=".png,.jpeg,.jpg" ng-files="getTheFiles($files)" ng-model='company.logo'> 在控制台中,所选图像的高度和宽度显示为0,0 我已经引用了这篇文章的答案(虽然没有被接受,但经过了5次投票) 谢谢你的帮助 $scope.imgpath = e.target.result;

我想在用户选择要上载的文件时检查图像的尺寸

到目前为止,我已经完成了以下代码:

HTML

<input type="file" accept=".png,.jpeg,.jpg"  ng-files="getTheFiles($files)" ng-model='company.logo'>
在控制台中,所选图像的高度和宽度显示为0,0

我已经引用了这篇文章的答案(虽然没有被接受,但经过了5次投票)

谢谢你的帮助

$scope.imgpath = e.target.result;
应该是

$scope.imgpath.src = e.target.result;

好吧,我试过这个代码,它成功了:

                var fileReader = new FileReader();
                $scope.imgpath = new Image();
                fileReader.onload = function (event) {
                    $scope.imgpath.src = event.target.result;
                    $scope.imgpath.onload = function(){
                        console.log(this.width, this.height);
                    };
                };

资料来源:

是的,应该是这样,但我仍然无法获得尺寸。
                var fileReader = new FileReader();
                $scope.imgpath = new Image();
                fileReader.onload = function (event) {
                    $scope.imgpath.src = event.target.result;
                    $scope.imgpath.onload = function(){
                        console.log(this.width, this.height);
                    };
                };