473,769 Members | 2,103 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getting width and Height of an Image Before uploading

30 New Member
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="javas cript">
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 4513
dasrasmikant
30 New Member
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="showI mage(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 Recognized Expert Top Contributor
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
dasrasmikant
30 New Member
so how can I do it. Is it possible by any server side scripting language
May 1 '08 #4
hsriat
1,654 Recognized Expert Top Contributor
Do NOT double post...
May 1 '08 #5
hsriat
1,654 Recognized Expert Top Contributor
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
dasrasmikant
30 New Member
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 Recognized Expert Moderator MVP
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
17482
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
72124
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 regardless how big the originals are. The height should be adjusted proportional so that the resulting thumbnail is not distorted. But as far as I know there is no such attribute like <IMG SRC=...... WIDTH=70 HEIGHT="Adjust proportional to...
1
2560
by: Pums | last post by:
How to get the information(like height, width) of an image to be uploaded?
4
1692
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 copies of the files. There are various scripting and "active" technologies enabled on the server: ASP.NET ASP Front Page Extensions Perl
7
6102
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 collect the pixel values as quickly as possible (like one row at a time)? what about setting (or changing) the pixel values back onto the bitmap?
7
2396
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 when you click a button. The button is an invisible GIF with an anchor that calls slide() onClick. The animation works fine in IE but in Firefox I'm getting a series of afterimages as the function moves the layer to the goal. The image is painted...
4
6224
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 Struts: import java.io.File; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Enumeration; import java.util.Iterator;
1
4199
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="" /><!--image in question--> <div id="closeAll" onclick="closeAll();">X</div> </div>
2
1718
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
9579
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9416
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10199
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9850
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7396
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5293
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3948
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3551
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.