WordPress.org

Ready to get started?Download WordPress

Forums

Getting image dimensions via javascript (5 posts)

  1. adnanoner
    Member
    Posted 1 year ago #

    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!

  2. Andrew Bartel
    Member
    Posted 1 year ago #

  3. adnanoner
    Member
    Posted 1 year ago #

    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.

  4. Andrew Bartel
    Member
    Posted 1 year ago #

    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.

  5. adnanoner
    Member
    Posted 1 year ago #

    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).

Topic Closed

This topic has been closed to new replies.

About this Topic