How to get the dimensions of an image in JavaScript

1 Answer

0 votes
const img = new Image();

img.src = 'https://www.collectivesolver.com/images/grammarly-grammar-checker.png';

img.onload = function() {
  console.log('width: ' + this.width)
  console.log('height: '+ this.height);
}




/*
run:

"width: 250"
"height: 250"

*/

 



answered Jan 29, 2022 by avibootz

Related questions

2 answers 210 views
1 answer 193 views
1 answer 122 views
...