Extract Width and Height of image
- From: SM <servandomontero@xxxxxxxxx>
- Date: 29 Apr 2007 20:42:52 -0700
Hello,
I've created a Unordered list with images using the Javascript DOM,
and i want to set up the width and height attributes of the image...
The problem is that most images vary in size.
Here's my question:
Knowing the filepath of the image, is it possible to extract the width
and height? If yes, how...
Thanks
Marco
....
var ul = document.createElement('ul');
for(var i=0; i<lstThumbnail.length; i++)
{
var path = lstThumbnail[i].path;
var li = document.createElement('li');
var a = document.createElement('a');
//assign 'href' attribute to element a
a.setAttribute('href', '#');
//create img element, assign the attributes: src, alt, width,
height
var img = document.createElement('img');
img.setAttribute('src', path);
img.setAttribute('alt', noimageTxt);
img.setAttribute('width', ???); <--- EXTRACT WIDTH AUTOMATIC
img.setAttribute('height', ???); <--- EXTRACT HEIGHT AUTOMATIC
//add <img> to <a>
a.appendChild(img);
//add <a> <li>
li.appendChild(a);
//add <li> to <ul>
ul.appendChild(li);
}
....
.
- Prev by Date: Re: This small piece of code works in Firefox but not in IE 7... why?
- Next by Date: Good practice question: Declaring/Initializing variables inside or outside a loop ?
- Previous by thread: FAQ Topic - How do I generate a random integer from 1 to N?
- Next by thread: Good practice question: Declaring/Initializing variables inside or outside a loop ?
- Index(es):
Relevant Pages
|