Check image width and height before upload with Javascript

前端 未结 8 817
情歌与酒
情歌与酒 2020-11-22 14:53

I have a JPS with a form in which a user can put an image:

Photo (max 240x240 and 100 kb):
8条回答
  •  余生分开走
    2020-11-22 15:38

    I agree. Once it is uploaded to somewhere the user's browser can access then it is pretty easy to get the size. As you need to wait for the image to load you'll want to hook into the onload event for img.

    var width, height;
    
    var img = document.createElement("img");
    img.onload = function() {
        // `naturalWidth`/`naturalHeight` aren't supported on 

提交回复
热议问题