473,396 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

getting width and Height of an Image Before uploading

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
7 4493
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
1,654 Expert 1GB
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
so how can I do it. Is it possible by any server side scripting language
May 1 '08 #4
hsriat
1,654 Expert 1GB
Do NOT double post...
May 1 '08 #5
hsriat
1,654 Expert 1GB
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
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
16,027 Expert Mod 8TB
Please do not double post. Threads merged.

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

Moderator.
May 1 '08 #8

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

Similar topics

5
by: ok | last post by:
Hello, Q: How do I get image width and height before uploading an image? This because, I want to restrict people uploading huge files. Thanks in advance
9
by: Wladimir Borsov | last post by:
As well known for <IMG ...> tags in web pages a width and a height attribute can be applied. What I want to do now is to fix the width for ALL the images on my web page to exactly lets say 70 pixel...
1
by: Pums | last post by:
How to get the information(like height, width) of an image to be uploaded?
4
by: Dotcom | last post by:
I have an ASP.NET application that is mysteriously acquiring height and width attributes on a particular IMG element on multiple pages. This is not being caused by someone editing or uploading new...
7
by: chuck | last post by:
I load a bitmap using GDI+ now, I want to collect all the pixel values, (in RGB but without the A component) onto a color array, say... dim btmp1(,) as color is there a method that can help me...
7
by: raylaur | last post by:
I'm using a javascript "slide" function to move a <div> layer in 10 pixel increments from one location on a page to another. The layer contains a GIF image. It's basically a side panel that flies out...
4
by: AshishMishra16 | last post by:
HI friends, I am using the Flex to upload files to server. I m getting all the details about the file, but I m not able to upload it to Server. Here is the code i m using for both flex & for...
1
epots9
by: epots9 | last post by:
I have a image inside of a div <div id="image"> <div id="loader"> <img id="loaderImage" src="assets/loader.gif" alt="loading..." /> </div> <div id="loaded"> <img id="picture" src="" alt=""...
2
by: dasrasmikant | last post by:
Hy experts, I want to send a width and height of an image to the database while uploading it. Can any one guide me?? Thanks
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.