'How to get image Height and Width while uploading image in React?
Is there any way to get Image Height and Width while uploading image...
I am trying the code below but always getting 0 0:
const uploadedImage = e.target.files[0];
var image = new Image();
image.src = uploadedImage;
console.log(image.naturalWidth,image.naturalHeight);
How Can I Solve this?
Solution 1:[1]
var _URL = window.URL || window.webkitURL;
$("#file").change(function (e) {
var file, img;
if ((file = this.files[0])) {
img = new Image();
var objectUrl = _URL.createObjectURL(file);
img.onload = function () {
alert(this.width + " " + this.height);
_URL.revokeObjectURL(objectUrl);
};
img.src = objectUrl;
}
});
You may find details HERE
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tanjin Alam |
