Support » Fixing WordPress » 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)
  • 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.

    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.

    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.