1

I have an input file tag and I want to get the height and width of user selected image.

    class AtomicImage  extends Component {
        constructor(props) {
        super(props);
        this.state = {dimensions: {}};
        this.onChange = this.onChange.bind(this);
    }
    onChange = (e) => {
        height = ?,
        width = ?
    }
    render(){
        const {src} = this.props;
        const {width, height} = this.state.dimensions;

        return (<div>
            <input type="file" onChange={onChange}>
            </div>
           );
        }
    }
vaibhav kanmeriya
  • 143
  • 1
  • 1
  • 9
  • 1
    After you upload the file, you have its object from event.target, then check out one of the answers mentioned, another resource: https://stackoverflow.com/questions/8903854/check-image-width-and-height-before-upload-with-javascript – Dennis Vash Oct 02 '20 at 13:16
  • @DennisVash Thanks for the comment. It's really appreciated. – vaibhav kanmeriya Oct 03 '20 at 04:17

0 Answers0