0

I'm new to programming, I tried to find the height and width of uploaded image so that I can set a condition based on image height and width.If it is valid I can set image path in state of my React Component.Thank you....

`

onSelectFile = e => {
    if (e.target.files && e.target.files.length > 0) {
        const reader = new FileReader();
        var image=new Image()
        reader.addEventListener('load', () =>
        image.addEventListener('load', () =>{
            if(this.height>600||this.width>600){
                this.setState({ src: reader.result }, () => {
                    this.toggleTab("2")
                }
                else if(){
                    alert("Image is too small")
                }

            }),
            );
            reader.readAsDataURL(e.target.files[0]);
        }
    };
    <input type="file" id="fileInput" name="fileInput" onChange= .
    {this.onSelectFile}/>
}

`

daedsidog
  • 1,732
  • 2
  • 17
  • 36
Pavan Kusunuri
  • 327
  • 5
  • 20

1 Answers1

0

First, you have an else if clause with no condition in your code.

 else if(){  // <------------- Problem
       alert("Image is too small")
     }

Second, to get the dimensions of the file you can use the .width and .height properties.

tomerpacific
  • 4,704
  • 13
  • 34
  • 52