I have the following input element: <input type="file" accept="image/*" multiple="">
inside of a div
with the id ImageUploader
.
The uploaded images get automatically cropped, but I have no influence on that functionality.
JS:
var upload = document.getElementById("ImageUploader");
upload.onchange=function(event){
let img = new Image()
//console.log(event);
img.src = window.URL.createObjectURL(event.target.files[0]);
img.onload = () => {
console.log(event.target.files[0].initialCroppedAreaPixels);
console.log(event.target.files[0]);
};
};
The strange thing is that for some images it is able to log the cropped size to the console, but for other images event.target.files[0].initialCroppedAreaPixels
just returns undefined, which I don't understand, because in the next line, the file that gets logged into the console always has the initialCroppedAreaPixels
attribute.
What's the issue there?