How to get image dimensions from URL (JavaScript)

Let's consider an example of how you can get an image dimensions, knowing its URL.

We create an Image object, then assign a link to it and then after image load we can find out the width and height of the object.

An example:

const img = new Image();
img.src = ''; // change to your URL
img.onload = function() {

This example should print to the console the width and height of the image you have specified in the URL.


No comments yet, you can leave yours: