How do we get image width height in angular 5, before uploading a file?

1,711 views
Skip to first unread message

Raghu Ram

unread,
Jun 10, 2019, 5:32:47 AM6/10/19
to Angular and AngularJS discussion
Hi All,

Please reply me, how do we get image width & height in angular 5, before uploading a file.

Regards
Raghu

Sander Elias

unread,
Jun 14, 2019, 4:26:12 AM6/14/19
to Angular and AngularJS discussion
Hi Raghu,

There is nothing specific to angular about this. do something like this in your (change) handler:

checkDimenstions(ev: Event) {
if (ev && ev.target && ev.target.files) {
const file = ev.target.files[0];
const img = new Image();
img.onload = function() {
alert('Width:' + this.width + ' Height: ' + this.height);
};
img.src = URL.createObjectURL(file);
}
}

(completely untested!)

Regards
Sander

Reply all
Reply to author
Forward
0 new messages