How to get image size (height & width) using JavaScript?

前端 未结 29 3723
忘了有多久
忘了有多久 2020-11-21 05:23

Are there any JavaScript or jQuery APIs or methods to get the dimensions of an image on the page?

29条回答
  •  生来不讨喜
    2020-11-21 05:45

    function outmeInside() {
    var output = document.getElementById('preview_product_image');
    
     if (this.height < 600 || this.width < 600) {
         output.src = "http://localhost/danieladenew/uploads/no-photo.jpg";
         alert("The image you have selected is low resloution image.Your image width=" + this.width + ",Heigh=" + this.height + ". Please select image greater or equal to 600x600,Thanks!");
     } else {
         output.src = URL.createObjectURL(event.target.files[0]);
    
     }
     return;
    
     }
    
     img.src = URL.createObjectURL(event.target.files[0]);
    }
    

    this work for multiple image preview and upload . if you have to select for each of the images one by one . Then copy and past into all the preview image function and validate!!!

提交回复
热议问题