like:
<img src="http://www.google.com/intl/en_ALL/images/srpr/logo1w.png">
i want get logo1w.png file size 7.3kb
how to implement it?
Check out this : Determining image file size + dimensions via Javascript?
You could do an HTTP HEAD request for the image URL. This will return the HTTP headers, which include the content-length (a.k.a. file size). This does require an additional request to the server, which is not very efficient when the image is generated instead of being served statically.
I don't know of any single way to consistently get the exact file size, but if you're willing to jump through some hoops, you could:
1) Estimate based on the dimensions and the file type. Because of compression techniques there's some wide variation, but you could probably run some statistics and come up with a half-decent heuristic.
2) In IE, use the fileSize
property of an image. In other browsers that support Canvas, use the technique described in this question on getting image data in JavaScript to grab the dataURL, then do the math (multiply by 3/4, since base64 is a 4/3 size increase).
Edit
3) The suggestion others have given (particularly as elaborated in the question linked in Fabien Bernede's answer) about getting HTTP Headers is brilliant AND precise. Probably runs afoul of cross-domain restrictions in some cases, but still probably the most consistent and effective method.
You cannot in javascript (sorry even magical jQuery cannot help here!). You would need a server side script to fetch the image for you and calculate the size which you could return to your page.
Note - downvoters beware, the OP does not own the google domain!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With