S
SM
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.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);
}
....
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.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);
}
....