SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: this.image?

  1. #1
    Free Geek computerages's Avatar
    Join Date
    Oct 2004
    Location
    /dev/null
    Posts
    1,071
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question this.image?

    Hi,

    I was just whether is there any way to find out the dimensions of an image file using JavaScript. Let's say I have
    HTML Code:
    <img src=&quot;img.gif&quot; />
    and I want to find out the dimensions (width and height) of it, is there anything JavaScript that could do it for me instead of me manually looking for it?

    I hope you understood the point of my question, let me know if anything is unclear.

    thx.

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Image objects have "width" and "height" properties. If the img had id='img1' then...
    Code:
    window.onload = function()
    {
      var i = document.getElementById('img1');
      if (i) alert('width: ' + i.width + ', height: ' + i.height);
    }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •