# Check Image File Size

**URL:** <https://www.ruby-forum.com/t/check-image-file-size/134125>\
**Category:** Ruby\
**Created:** [April 8, 2008, 3:54am UTC](https://www.ruby-forum.com/t/check-image-file-size/134125 "2008-04-08T03:54:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![superfly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/48db29/32.png) [@superfly](https://www.ruby-forum.com/u/superfly)\
**Post date:** [April 8, 2008, 3:54am UTC](https://www.ruby-forum.com/t/check-image-file-size/134125/1 "2008-04-08T03:54:21Z")

</div>

Hello everybody,

I’m looking for a way that I could insert a URL for an image that is  
online and have it tell me what size it is?

I’ve been messing around with File.size? and file.size and havn’t quite  
gotten it to work, am I missing something?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![superfly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/48db29/32.png) [@superfly](https://www.ruby-forum.com/u/superfly)\
**Post date:** [April 8, 2008, 4:56am UTC](https://www.ruby-forum.com/t/check-image-file-size/134125/2 "2008-04-08T04:56:01Z")

</div>

how about

require ‘open-uri’  
open(ARGV[0]) { |f| puts f.size }

i’m not sure if this will GET the file even if you don’t access its  
data, because the size info should already have been communicated  
within http, in that case there might be are more convinient way only  
using http probing for the size.

g phil

---

<div class="post-metadata">

**Author:** ![superfly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/48db29/32.png) [@superfly](https://www.ruby-forum.com/u/superfly)\
**Post date:** [April 8, 2008, 5:00am UTC](https://www.ruby-forum.com/t/check-image-file-size/134125/3 "2008-04-08T05:00:07Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

Tj Superfly wrote:  
| Hello everybody,  
|  
| I’m looking for a way that I could insert a URL for an image that is  
| online and have it tell me what size it is?  
|  
| I’ve been messing around with File.size? and file.size and havn’t quite  
| gotten it to work, am I missing something?

Have you tried downloading the image? Or at least an HTTP connection?

AFAIK, HTTP doesn’t provide an option to detect the size of a file  
without downloading (might be wrong, never messed around with HTTP  
headers). (S)FTP might, though, but that requires an open FTP  
connection.

In any case, you’ll need an open network connection to the file.

* * *

Phillip G.  
Twitter: [twitter.com/cynicalryan](http://twitter.com/cynicalryan)

~ That’s the difference between me and the rest of the world!  
Happiness  
isn’t  
good enough for me! I demand euphoria! – Calvin  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.8 (MingW32)  
Comment: Using GnuPG with Mozilla - [http://enigmail.mozdev.org](http://enigmail.mozdev.org)

iEYEARECAAYFAkf635oACgkQbtAgaoJTgL91cwCaAxGjpnWuNkt51jsYXU5PpZwO  
l+0AnRQctV3ydxCp4hHU8dhcBOHzJp9+  
=BEvE  
-----END PGP SIGNATURE-----
