Title: Getting image dimensions via javascript
Last modified: August 20, 2016

---

# Getting image dimensions via javascript

 *  [adnanoner](https://wordpress.org/support/users/adnanoner/)
 * (@adnanoner)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/getting-image-dimensions-via-javascript/)
 * Hi everybody,
 * I need to get image dimensions of a wordpress image through javascript. Is there
   anyway I can do this or is there a way that wordpress automatically appends image
   dimensions to the uploaded image link?
 * so my code kind of looks like this:
 *     ```
       $('body').append('<img src="image.jpg" width="' + w + '" height="' + h + '" alt="" />');
       ```
   
 * Cheers!

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Andrew Bartel](https://wordpress.org/support/users/andrew-bartel/)
 * (@andrew-bartel)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/getting-image-dimensions-via-javascript/#post-3251550)
 * [http://stackoverflow.com/questions/1944280/determine-original-size-of-image-cross-browser](http://stackoverflow.com/questions/1944280/determine-original-size-of-image-cross-browser)
 *  Thread Starter [adnanoner](https://wordpress.org/support/users/adnanoner/)
 * (@adnanoner)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/getting-image-dimensions-via-javascript/#post-3251552)
 * Hi thanks Andrew. I’d rather though have a way to have in hardcoded in the uploaded
   image’s link since the img is otherwise allocated in the memory.
 *  [Andrew Bartel](https://wordpress.org/support/users/andrew-bartel/)
 * (@andrew-bartel)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/getting-image-dimensions-via-javascript/#post-3251558)
 * Sorry what?
 * The image has to be loaded for you to retrieve the dimensions. The `<a>` tag 
   surrounding it isn’t going to store any information about the image either.
 *  Thread Starter [adnanoner](https://wordpress.org/support/users/adnanoner/)
 * (@adnanoner)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/getting-image-dimensions-via-javascript/#post-3251566)
 * Hi sorry did not get my point across. So let’s forget about the javascript. When
   I upload an image wordpress knows its dimensions. Lets say the image is called
   image.jpg . I now want wordpress to rename the image url to image-w-180-h-200.
   jpg for example (where the image has a width of 180 pixels and a height of 200
   pixels). That way I can retrieve these parameters with javascript and not preload
   the image.
    So basically this would be a server-side solution instead (which 
   seems better to me since we can’t get the image dimensions without preoloading
   it first).

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Getting image dimensions via javascript’ is closed to new replies.

## Tags

 * [image dimensions](https://wordpress.org/support/topic-tag/image-dimensions/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [adnanoner](https://wordpress.org/support/users/adnanoner/)
 * Last activity: [13 years, 6 months ago](https://wordpress.org/support/topic/getting-image-dimensions-via-javascript/#post-3251566)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
