Determining width and height of image files


#1

I’m trying to figure out how to determine the width and height of images
that are uploaded through my app. Either from the posted data or the
file I save to disk. I’ve been searching around for info but no luck;
I’m completely at a loss. Any suggestions or pointers would be great.

Project background:
The site is an artists portfolio site. The images are thumbnails and
large pictures of her paintings. Rather then force her type in the width
and height for every image I’d like to be able to detect those
programmatically.

  • William

#2

This will help you out. Just gotta parse out what you need.

http://www.bigbold.com/snippets/tag/rmagick

Google is your friend.

Bob S.
http://www.railtie.net/


#3

That example requires rmagick. Is there a way to do this without extra
modules?

Thanks for the link. I found it once before, forgot to bookmark it, and
was never able to find it again. From what I’ve seen, it looks like a
good site.


#4

William LeFevre wrote:

That example requires rmagick. Is there a way to do this without extra
modules?

Not unless you want to write your own code to parse the information out
of the image files… It’s not too hard for most common file types, but
it’d be far easier to get RMagick working, because that’ll give you a
way in to automatically generating thumbnails from originals, and so on.


Alex


#5

Not unless you want to write your own code to parse the information out
of the image files…

That’s what I’m after. Right now I don’t need all image processing
capabilities; I just need the width and height.


#6

Sweet. That looks perfect. I’ll dig into that tonight.


#7

On Jan 29, 2006, at 10:00 AM, William LeFevre wrote:


Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails

Try this:

http://www.bigbold.com/snippets/posts/show/805

Cheers-
-Ezra Z.
WebMaster
Yakima Herald-Republic Newspaper
removed_email_address@domain.invalid
509-577-7732


#8

Try this: http://www.bigbold.com/snippets/posts/show/805

It doesn’t depend on rmagick; it parses the file headers instead.


#9

Looking at this code, doesn’t it assume a certain “endian-ness”?