Closed Thread Icon

Topic awaiting preservation: Retrieve picture size during preload. Pages that link to <a href="https://ozoneasylum.com/backlink?for=8479" title="Pages that link to Topic awaiting preservation: Retrieve picture size during preload." rel="nofollow" >Topic awaiting preservation: Retrieve picture size during preload.\

 
Author Thread
Sam
Bipolar (III) Inmate

From: Belgium
Insane since: Oct 2002

posted posted 01-20-2003 09:31

Hi,

In an onLoad trigger I want to retrieve the picture size so I make an image variable and assign the url of the picture to it. Next I try to retrieve the width and height of the image variable. I do this as follows:

code:
img = new Image();
img.src = l_pic_url;
l_pw = img.width;
l_ph = img.height;


The problem I have is that variable l_pw and l_pw are very often 0 (very often on my local PC, always on the server). I assume this is because the picture isn't entirely loaded when I retrieve its size. Does anyone know how I can wait until the image is loaded?

Sam

Clay
Nervous Wreck (II) Inmate

From: Utreg, NL
Insane since: Nov 2002

posted posted 01-20-2003 09:56

Images have their own onload handler, so one way to do this would be to put a hidden (visibility:hidden, display:none) "buffer" image in your page, and change its source to the desired image. the img tag would have an onload handler, which is autmagically fired when the new image is loaded. The other way is to create images on the fly with dom script, and attach the onload with js. Dunno if a new Image() can have a .onload ref, havent tried.

Bugimus
Maniac (V) Mad Scientist

From: New California
Insane since: Mar 2000

posted posted 01-20-2003 10:15

Or you may want to just trigger off of the document.onload event and put all your image detection code in a function that is called by that. It depends on how detailed you need to get.

. . : slicePuzzle

Sam
Bipolar (III) Inmate

From: Belgium
Insane since: Oct 2002

posted posted 01-20-2003 11:08

The onLoad event of an IMG tag...

... very nice invention!




« BackwardsOnwards »

Show Forum Drop Down Menu