473,239 Members | 1,706 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,239 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 4486
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: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.