Connect with Expertise | Find Experts, Get Answers, Share Insights

Reading Image File Size

Wazz Up
 
Posts: n/a
#1: Jul 23 '05
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
 
Posts: n/a
#2: Jul 23 '05

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

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


--

Martin Honnen
http://JavaScript.FAQTs.com/
Wazz Up
 
Posts: n/a
#3: Jul 23 '05

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.

Evertjan.
 
Posts: n/a
#4: Jul 23 '05

re: Reading Image File Size


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)
Evertjan.
 
Posts: n/a
#5: Jul 23 '05

re: Reading Image File Size


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

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.
Closed Thread