javascript/jquery size and dimension of uploaded image file

前端 未结 3 848
遇见更好的自我
遇见更好的自我 2021-02-04 13:30

I need to display the image size in kilobyte and the dimension (height, width) using javascript/jquery. I came across few similar posts, but none could help me. I have two set o

3条回答
  •  别跟我提以往
    2021-02-04 14:23

    How to get image width and height using jquery

    Find out the image width and height during image upload using jQuery

    Size and dimension of upload image file

    var _URL = window.URL || window.webkitURL;
    $("#myfile").change(function (e) {
        var file, img;
        if ((file = this.files[0])) {
            img = new Image();
            img.onload = function () {
                var wid = this.width;
                var ht = this.height;
    
                alert(this.width + " " + this.height);
                alert(wid);
                alert(ht);
            };
    
            img.src = _URL.createObjectURL(file);
        }
    });
    

提交回复
热议问题