By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,147 Members | 744 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,147 IT Pros & Developers. It's quick & easy.

Image dimensions

P: 1
I am building a photo gallery using code which creates thumbnails of a specific size from any image. When clicked the thumbnail expands dynamically to a pre-determined size.
The sizes of the thumbnails and the enlarged image are set via variables. To work properly, all the original images must be the same dimensions which means a great deal of editing and cropping before the images can be posted. And portrait images sometimes cannot be cropped to fit.
My code starts by creating thumbnails from the original image and as such doesn't need to know the orginal dimensions because I don't much care if the thumbnail distorts.
But I need to be able to obtain the original image dimensions so that I can apply a test when enlarging and use different final dimensions depending on the originals.
To keep it simple I only need to check whether the original is portrait or landscape.
All my images are either 600 x 450 landscape or 450 x 600 portrait. So I only need to check one dimension, say the width.
But how can I get that dimension?
I have a feeling getElementById may have the answer but I'm not yet comfortable with the COM model.
Can anybody suggest a snippet that might do the job?

John
Sep 8 '06 #1
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
If the image has an id of "image":
[html]<img id="image" ...>[/html]to get the width:
Expand|Select|Wrap|Line Numbers
  1. var width = document.getElementById("image").width;
May 6 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.