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

getting width and Height of an Image Before uploading

P: 30
Dear Experts,
I am falling in a trouble and need your help for solving it

I want to get the width and heignt of an image before uploading it. Below is my code

<script language="javascript">
Expand|Select|Wrap|Line Numbers
  1. function showImage(i)
  2. {
  3.     x=new Image;
  4.     x.src=i;            
  5.  
  6.  iw=x.width;
  7. ih=x.height;
  8. alert("Image width is: "+iw+" pixels, and image height is: "+ih+" pixels.");
  9.  
  10.         }
  11.  
</script>
May 1 '08 #1
Share this Question
Share on Google+
7 Replies


P: 30
Dear Experts,
I am falling in a trouble and need your help for solving it

I want to get the width and heignt of an image before uploading it. Below is my code

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2. function showImage(i)
  3. {
  4.     x=new Image;
  5.     x.src=i;    
  6.                iw=x.width;
  7.                ih=x.height;
  8.              alert("Image width is: "+iw+" pixels, and image height is: "+ih+" pixels.");
  9. }
  10. </script>
In HTML Part
[HTML]<input name="fileImage" type="file" size="25" onchange="showImage(this.value)" />[/HTML]

But when ever I am uploading any image its showing 0 pixels for both width and height.

Pls..
Thanks in advence.
May 1 '08 #2

hsriat
Expert 100+
P: 1,654
You can't do that before you upload it.

JS doesn't have access on the local files, so it can't do that. You can't even provide any local image as value to src of an image (img).

But you can upload the image with Ajax, and return the height and width back to the client after processing the image at server side.
May 1 '08 #3

P: 30
so how can I do it. Is it possible by any server side scripting language
May 1 '08 #4

hsriat
Expert 100+
P: 1,654
Do NOT double post...
May 1 '08 #5

hsriat
Expert 100+
P: 1,654
so how can I do it. Is it possible by any server side scripting language
Yes its possible in server side scripting. You may ask that in the forum dedicated for the language you are using.
May 1 '08 #6

P: 30
Yes its possible in server side scripting. You may ask that in the forum dedicated for the language you are using.
Ok thanks.
I will be post it an ASP section.
May 1 '08 #7

acoder
Expert Mod 15k+
P: 16,027
Please do not double post. Threads merged.

Also remember to use [code] tags when posting code.

Moderator.
May 1 '08 #8

Post your reply

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