Reading Image File Size

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Wazz Up

    Reading Image File Size

    Is there a way to read the file size of images with JavaScript ? I know
    how to read the width and height.

    Later, Art.

  • Martin Honnen

    #2
    Re: Reading Image File Size



    Wazz Up wrote:
    [color=blue]
    > Is there a way to read the file size of images with JavaScript ?[/color]

    I think only IE exposes a property named fileSize e.g.

    var img = new Image();
    img.onload = function (evt) {
    alert(this.file Size);
    }
    img.src = 'kiboInside.gif '

    but other browsers (at least Mozilla and Opera) do not provide that
    property.


    --

    Martin Honnen

    Comment

    • Wazz Up

      #3
      Re: Reading Image File Size

      Thanks for your reply and info Martin.

      Because of the lack of cross browser compatibility, perhaps I should
      wait until I learn a server side language. Of course I got a long way to
      o with JavaScript before I go there.

      Later, Art.

      Comment

      • Evertjan.

        #4
        Re: Reading Image File Size

        Wazz Up wrote on 27 dec 2004 in comp.lang.javas cript:
        [color=blue]
        > Thanks for your reply and info Martin.
        >
        > Because of the lack of cross browser compatibility, perhaps I should
        > wait until I learn a server side language. Of course I got a long way to
        > o with JavaScript before I go there.
        >[/color]

        Javascript is also a serverside language under ASP.

        Don't say Javascript if you mean clientside script.

        --
        Evertjan.
        The Netherlands.
        (Please change the x'es to dots in my emailaddress)

        Comment

        • Evertjan.

          #5
          Re: Reading Image File Size

          Martin Honnen wrote on 27 dec 2004 in comp.lang.javas cript:
          [color=blue]
          > I think only IE exposes a property named fileSize e.g.
          >
          > var img = new Image();
          > img.onload = function (evt) {
          > alert(this.file Size);
          >}
          > img.src = 'kiboInside.gif '
          >[/color]

          I don't know what the "evt" is for.

          ========== try this [IE6]:

          <img src = 'kiboInside.jpg '
          onload = "this.alt=this. fileSize+' bytes'">

          --
          Evertjan.
          The Netherlands.
          (Please change the x'es to dots in my emailaddress)

          Comment

          • RobG

            #6
            Re: Reading Image File Size

            Wazz Up wrote:
            [...][color=blue]
            > I know how to read the width and height.[/color]

            For some browsers, width and height attributes will only be "readable"
            if set. If an image is placed with:

            <img src="someImage. jpg" alt="an image">

            and you try to read the width or height, you will get undefined.

            --
            Rob.

            Comment

            Working...