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.

3
  • This is NOT a duplicate question. You can clearly see my question is different to the one linked. Commented Mar 19, 2015 at 17:16
  • It is the same question. It's just that the answer isn't what you'd hoped. Commented Mar 19, 2015 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. Commented Mar 19, 2015 at 17:37

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

1 Comment

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!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.