getting width and Height of an Image Before uploading

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dasrasmikant
    New Member
    • Jan 2008
    • 30

    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="javas cript">
    [CODE=javascript]function showImage(i)
    {
    x=new Image;
    x.src=i;

    iw=x.width;
    ih=x.height;
    alert("Image width is: "+iw+" pixels, and image height is: "+ih+" pixels.");

    }
    [/CODE]
    </script>
    Last edited by acoder; May 1 '08, 09:58 AM. Reason: Added code tags
  • dasrasmikant
    New Member
    • Jan 2008
    • 30

    #2
    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

    Code:
    <script language="javascript">
    function showImage(i)
    {
    	x=new Image;
    	x.src=i;	
                   iw=x.width;
                   ih=x.height;
                 alert("Image width is: "+iw+" pixels, and image height is: "+ih+" pixels.");
    }
    </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.

    Comment

    • hsriat
      Recognized Expert Top Contributor
      • Jan 2008
      • 1653

      #3
      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.

      Comment

      • dasrasmikant
        New Member
        • Jan 2008
        • 30

        #4
        so how can I do it. Is it possible by any server side scripting language

        Comment

        • hsriat
          Recognized Expert Top Contributor
          • Jan 2008
          • 1653

          #5
          Do NOT double post...

          Comment

          • hsriat
            Recognized Expert Top Contributor
            • Jan 2008
            • 1653

            #6
            Originally posted by dasrasmikant
            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.

            Comment

            • dasrasmikant
              New Member
              • Jan 2008
              • 30

              #7
              Originally posted by hsriat
              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.

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                Please do not double post. Threads merged.

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

                Moderator.

                Comment

                Working...