363,924 Members | 2575 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

Reading Image File Size

Wazz Up
P: n/a
Wazz Up
Is there a way to read the file size of images with JavaScript ? I know
how to read the width and height.

Later, Art.

Jul 23 '05 #1
Share this Question
Share on Google+
5 Replies


Martin Honnen
P: n/a
Martin Honnen


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.fileSize);
}
img.src = 'kiboInside.gif'

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


--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2

Wazz Up
P: n/a
Wazz Up
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.

Jul 23 '05 #3

Evertjan.
P: n/a
Evertjan.
Wazz Up wrote on 27 dec 2004 in comp.lang.javascript:
[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)
Jul 23 '05 #4

Evertjan.
P: n/a
Evertjan.
Martin Honnen wrote on 27 dec 2004 in comp.lang.javascript:
[color=blue]
> I think only IE exposes a property named fileSize e.g.
>
> var img = new Image();
> img.onload = function (evt) {
> alert(this.fileSize);
>}
> 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)
Jul 23 '05 #5

RobG
P: n/a
RobG
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.
Jul 23 '05 #6

Post your reply

Help answer this question



Didn't find the answer to your JavaScript / Ajax / DHTML question?

You can also browse similar questions: JavaScript / Ajax / DHTML