Check image width and height before upload with Javascript

前端 未结 8 748
情歌与酒
情歌与酒 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:57

        const ValidateImg = (file) =>{
            let img = new Image()
            img.src = window.URL.createObjectURL(file)
            img.onload = () => {
                if(img.width === 100 && img.height ===100){
                    alert("Correct size");
                    return true;
                }
                alert("Incorrect size");
                return true;
            }
        }

提交回复
热议问题