Posts Photos Archives About
Rik Heywood said...

Your server can find out the dimensions of the images and send this information along when you request an image. Failing that, you will need to wait for the image to load before its dimensions will be available to javascript.

However, there is another way. Request the image, telling the server the dimensions of the space you have. It can then generate a suitable version of the image and cache this, before sending the image that is already exactly the right size down to the browser.

Update One other way, that may be acceptable to you is to set the container div like so...

.mydiv { overflow: hidden; }

Then set the image to be fixed in height and auto for width. This will cause over-wide images to be clipped on the left and right of the image. If this is acceptable in your case, then this is a very simple solution.