Determining width and height of image files

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

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

Google is your friend.

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

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.

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

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.

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

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


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

Try this:

Cheers-
-Ezra Z.
WebMaster
Yakima Herald-Republic Newspaper
[email protected]
509-577-7732

Try this: BigBold - Informasi Tentang Bisnis dan Marketing

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

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