reactjsdrag-and-dropfrontendreact-dropzone

How do I constrain the height and width of an image in React Dropzone?


<Dropzone onDrop={_aaaa} minSize={1024} maxSize={3072000} maxFiles={5}>
          {({ getRootProps, getInputProps, isDragActive, isDragAccept, isDragReject }) => {
            return (
              <div {...getRootProps({ className: "yyyy" })}>
                <p className="xxxx">Drag the files to this area.</p>
                <input {...getInputProps()} />
              </div>
            );
          }}</Dropzone>

I just want to upload 400x500 photos.


Solution

  • While the image is onload, the function gives me the width and height values.

        var image = new Image();    
    image.onload = function () {
        console.log('width', image.width);
        console.log('height', image.height);
    };