Is there a way in javascript to find out the size of an image you've just
preloaded?
I have the following object:
function tourImage(imgName) {
// used for passing image details to a function.
this.name=imgName;
//this.imgLoadImg = document.getElementById("imgLoadImg");
function preload(callback) {
this.img=new Image();
this.img.src=this.name;
// call tour.showPano when the image has loaded.
this.img.onLoad=this.runCallback(callback);
};
this.preload=preload;
function runCallback(cb) {
// first do what's needed for every image.
// puit this image into the hidden image container to find the size.
//this.imgLoadImg.src=this.name;
//this.width=this.imgLoadImg.width;
//this.height=this.imgLoadImg.height;
//this.imgLoadImg.src="";
this.height=tour.resolution;
*** // TODO - fix this so it finds the image size automatically.
this.width=tour.resolution*6.889;
this.ratio=this.width / this.height;
// then call the callback function.
cb();
}
this.runCallback=runCallback;
};
what I want to do is fix this so it finds out the size of the just-loaded
image by itself, so that the true image dimensions can be used to scale
the image properly.
I've tried using this.img.width; I've also tried loading the image into a
dummy img tag with no width and height properties to see if I can get the
details that way, but that doesn't work either.
can anyone suggest a good way of doing this?
--
http://www.niftybits.ukfsn.org/
remove 'n-u-l-l' to email me. html mail or attachments will go in the spam
bin unless notified with [html] or [attachment] in the subject line.