<input type="file" class="test" name="vend_logo" id="vend_logo">
$('.test').bind('change', function() {
var file = files[0]
var img = new Image();
var width = img.width;alert(width);
});
I wanted to alert the image width and height been uploaded. how can i do this ? I have used clientwidth
and also naturalwidth
but it is not displaying the correct value.
You can do something like this
$('.test').bind('change', function() {
if (file = this.files[0]) {
img = new Image();
img.onload = function() {
var width = this.width;
alert(width);
};
img.src = window.URL.createObjectURL(file);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="file" class="test" name="vend_logo" id="vend_logo">
Reference : Check image width and height before upload with Javascript
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With