# Get Image Dimensions Given Local File Path

**URL:** <https://www.ruby-forum.com/t/get-image-dimensions-given-local-file-path/81035>\
**Category:** Rails\
**Created:** [January 3, 2007, 8:01am UTC](https://www.ruby-forum.com/t/get-image-dimensions-given-local-file-path/81035 "2007-01-03T08:01:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![parrfolio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/47e85d/32.png) [@parrfolio](https://www.ruby-forum.com/u/parrfolio)\
**Post date:** [January 3, 2007, 8:01am UTC](https://www.ruby-forum.com/t/get-image-dimensions-given-local-file-path/81035/1 "2007-01-03T08:01:27Z")

</div>

Hi All,

I have an image file (.jpg) that I can open via File.open() and I am  
curious  
on the easiest way to get the dimensions of this file. I’d prefer this  
to  
be a ruby/rails way and not a javascript method. Basically, I am  
looking  
for a way to verify that when a user uploads an image file that it is  
not  
larger than x by y. I’ve been looking around the web and I’m having  
trouble  
finding a way to do this. Also, if there is a way to just resize any  
image  
over some pre-defined size that would work as well.

Thanks in advance,  
Ryan

–  
Ryan P.  
removed\_email\_address@domain.invalid

> **[Ryan Prins' Blog](http://www.lazyi.net)**
>
> Photos and fun from Seattle, WA

---

<div class="post-metadata">

**Author:** ![parrfolio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/47e85d/32.png) [@parrfolio](https://www.ruby-forum.com/u/parrfolio)\
**Post date:** [January 3, 2007, 8:03am UTC](https://www.ruby-forum.com/t/get-image-dimensions-given-local-file-path/81035/2 "2007-01-03T08:03:28Z")

</div>

Look at:

[http://www.simplesystems.org/RMagick/doc/comtasks.html](http://www.simplesystems.org/RMagick/doc/comtasks.html)

Ryan P. wrote:

> finding a way to do this. Also, if there is a way to just resize any
> 
> >

–  
View this message in context:  
[http://www.nabble.com/-Rails--Get-Image-Dimensions-Given-Local-File-Path-tf2912107.html#a8136651](http://www.nabble.com/-Rails--Get-Image-Dimensions-Given-Local-File-Path-tf2912107.html#a8136651)  
Sent from the RubyOnRails Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![parrfolio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/47e85d/32.png) [@parrfolio](https://www.ruby-forum.com/u/parrfolio)\
**Post date:** [January 3, 2007, 8:03am UTC](https://www.ruby-forum.com/t/get-image-dimensions-given-local-file-path/81035/3 "2007-01-03T08:03:29Z")

</div>

try FlexImage [http://beautifulpixel.com/flex\_image/index.html](http://beautifulpixel.com/flex_image/index.html)

It allows you to crop, resize, etc. checkout the RDoc link above, and  
see if that will work for you.

Matt

---

<div class="post-metadata">

**Author:** ![parrfolio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/47e85d/32.png) [@parrfolio](https://www.ruby-forum.com/u/parrfolio)\
**Post date:** [January 3, 2007, 10:21am UTC](https://www.ruby-forum.com/t/get-image-dimensions-given-local-file-path/81035/4 "2007-01-03T10:21:44Z")

</div>

There are RoR plugins that allow you to resize and validate image  
uploads. Try the file\_column plugin:

[http://www.kanthak.net/opensource/file\_column/](http://www.kanthak.net/opensource/file_column/)
