# How to find the dimensions of an uploaded image

**URL:** <https://www.ruby-forum.com/t/how-to-find-the-dimensions-of-an-uploaded-image/114840>\
**Category:** Rails\
**Created:** [September 18, 2007, 12:06am UTC](https://www.ruby-forum.com/t/how-to-find-the-dimensions-of-an-uploaded-image/114840 "2007-09-18T00:06:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![taro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/df705f/32.png) [@taro](https://www.ruby-forum.com/u/taro)\
**Post date:** [September 18, 2007, 12:06am UTC](https://www.ruby-forum.com/t/how-to-find-the-dimensions-of-an-uploaded-image/114840/1 "2007-09-18T00:06:13Z")

</div>

Hi! I’m trying to make a site that can upload image files, but  
instead of posting each picture as their size, I’d rather post them in  
thumbnails (thank goodness html can warp images for you). I need to  
know how I can find a dimension of an image WITHOUT using a plugin  
(the server I am soon uploading this to most likely won’t have that  
plugin…and I don’t feel like forcing the administrators to download  
it). Are there any methods to take care of this?

Thanks!

---

<div class="post-metadata">

**Author:** ![taro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/df705f/32.png) [@taro](https://www.ruby-forum.com/u/taro)\
**Post date:** [September 18, 2007, 12:08am UTC](https://www.ruby-forum.com/t/how-to-find-the-dimensions-of-an-uploaded-image/114840/2 "2007-09-18T00:08:13Z")

</div>

> Hi! I’m trying to make a site that can upload image files, but  
> instead of posting each picture as their size, I’d rather post them in  
> thumbnails (thank goodness html can warp images for you). I need to  
> know how I can find a dimension of an image WITHOUT using a plugin  
> (the server I am soon uploading this to most likely won’t have that  
> plugin…and I don’t feel like forcing the administrators to download  
> it). Are there any methods to take care of this?

This will work for most jpegs…

[http://pastie.caboo.se/98119](http://pastie.caboo.se/98119)

Don’t remember where I got it… probably off of pastie in the first  
place  
🙂

If you have other image types you could find code to handle those and  
work  
that in. PHP’s getimagesize() method does most of them… and they all  
do  
it about the same way (read some bytes, do some math).

-philip

---

<div class="post-metadata">

**Author:** ![taro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/df705f/32.png) [@taro](https://www.ruby-forum.com/u/taro)\
**Post date:** [September 18, 2007, 12:09am UTC](https://www.ruby-forum.com/t/how-to-find-the-dimensions-of-an-uploaded-image/114840/3 "2007-09-18T00:09:14Z")

</div>

I found some TCL code to do that here:

> **[Reading JPEG image dimensions](https://wiki.tcl-lang.org/page/Reading+JPEG+image+dimensions)**
>
> Tclers wiki

It shouldn’t be too hard to port that to ruby. 🙂

- Tyler

---

<div class="post-metadata">

**Author:** ![taro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/df705f/32.png) [@taro](https://www.ruby-forum.com/u/taro)\
**Post date:** [September 18, 2007, 12:34am UTC](https://www.ruby-forum.com/t/how-to-find-the-dimensions-of-an-uploaded-image/114840/4 "2007-09-18T00:34:17Z")

</div>

Hi, in addituion to what the others have posted, I would first check  
what  
plugins are available on the host.

Good luck,

-Conrad
