JavaScript program to get the dimensions of an image
Today, we are going to write a JavaScript program to get the dimensions of an image.
This is very easy. Before we start to write the program let's see the example first.
Example : get image dimensions from URL. #
<script> const img = new Image(); img.src = 'https://app.3schools.in/img/bg.png'; img.onload = function() { console.log('width ' + this.width) console.log('height '+ this.height); } </script>
The Image() constructor creates a new HTMLImageElement instance.
The src property is used to set the image URL.
And finally the onload() method is used to access the height and width of the image (when the image is completely loaded).
save
listen
AI Answer
JavaScript program to get the dimensions of an image
0
Today, we are going to write a JavaScript program to get the dimensions of an image. This…
asked
Apu
0 answers
2915
Today, we are going to write a JavaScript program to get the dimensions of an image. This…
Answer Link
answered
Apu