By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,811 Members | 1,623 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,811 IT Pros & Developers. It's quick & easy.

Reading Image File Size

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


P: n/a


Wazz Up wrote:
Is there a way to read the file size of images with JavaScript ?


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

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

P: n/a
Wazz Up wrote on 27 dec 2004 in comp.lang.javascript:
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.


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

P: n/a
Martin Honnen wrote on 27 dec 2004 in comp.lang.javascript:
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'


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

P: n/a
Wazz Up wrote:
[...]
I know how to read the width and height.


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

This discussion thread is closed

Replies have been disabled for this discussion.