如何使用javascript获取宽度和高度?

时间:2014-09-22 12:24:52

标签: javascript ajax

这是我的代码:

function uploadFile(){
            var file2 = document.getElementById('file1').files;
            for(var i = 0; i < file2.length; i++) {
                var file = file2[i];
                var formdata = new FormData(); // This is image
                formdata.append("file1", file[i]);
                var ajax = new XMLHttpRequest();
                ajax.upload.addEventListener("progress", progressHandler, false);
                ajax.addEventListener("load", completeHandler, false);
                ajax.addEventListener("error", errorHandler, false);
                ajax.addEventListener("abort", abortHandler, false);
                ajax.open("POST", "file_upload_parser.php");
                ajax.send(formdata);
            }
        }

如何从new FormData获取图片宽度和高度? 我需要这个用于裁剪图像

1 个答案:

答案 0 :(得分:2)

在这里回答:How to get image size (height & width) using JavaScript?

var width = file.clientWidth;
var height = file.clientHeight;