I`m creating a function to upload an image. But it won´t over 400px of height and 400px of width, this is part of the code
$(() => {
$(document).on('change', 'input', function (e) {
let file = event.target.files[0];
if (!file) {
e.preventDefault();
return;
}else{
let imageType = /image.*/;
if (!file.type.match(imageType)) {
e.preventDefault();
return;
}else {
let reader = new FileReader();
reader.onload = () => {
$('img').attr('src', reader.result);
}
reader.readAsDataURL(file);
}
}
//What to do here?
if ( width > 400 || height > 400) {
console.log('oversized');
}
});
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="file">
<img src="">
It is not working, how could I validate if the image and not the img
tag
is oversized, I created this code with Jquery to fast problem replication, but, if you can help me with vanilla Javascript, it will be awesome