0

I'm trying to find out if it's possible to get the dimensions of an image via jQuery or even vanilla JavaScript, but not one that is already in the page, an image location which is passed via a parameter.

Example:

myFunction('images/myImage.png');

When that path is passed into the JS function - is there a way to get the images dimensions at all?

Please note the differences in this question and other similar questions that ask how to get the dimensions for the image on the page; it is not a duplicate.

Brett
  • 19,449
  • 54
  • 157
  • 290
  • This is NOT a duplicate question. You can clearly see my question is different to the one linked. – Brett Mar 19 '15 at 17:16
  • It *is* the same question. It's just that the answer isn't what you'd hoped. – isherwood Mar 19 '15 at 17:17
  • @isherwood Ummm, no it is *not*. An image on a page is NOT the same as an image path being passed in via a parameter; if it was then you would be able to use the same solution. – Brett Mar 19 '15 at 17:37

1 Answers1

0

you can try this: (although it's javascript)

var img = new Image();
img.onload = function() {
  alert(this.width + 'x' + this.height);
}
img.src = 'http://www.google.com/intl/en_ALL/images/logo.gif';

How to get image size (height & width) using JavaScript?

Community
  • 1
  • 1
Dima Gimburg
  • 1,376
  • 3
  • 17
  • 35
  • Just got around to trying this out and it works well. Accessed the image width via `img.src` as I didn't need the `onload` stuff. Though apparently this question is a dupe lol.... but a different answer specific to my query solved my issue, fancy that lol - thanks man! – Brett Mar 20 '15 at 13:13