I have a file input that only accepts images. When the image loads, I add it to an Image
variable.
I'm trying to make the image have a max width. Here's my code:
const reader = new FileReader();
reader.readAsDataURL(e.target.files[0]);
reader.onload = function (loadEvt) {
var newImage = new Image();
newImage.src = loadEvt.target.result;
// do something with newImage
};
I tried doing: new Image(200, 'auto');
but it didn't keep the aspect ratio. How can I give a max width while still keeping the images original aspect ratio?