Please read for an updated status on RailsCasts:
Learn more or hide this
GitHub User: mdchaney
Please see this project on github:
It does what you need pretty easily. Just stick it in your lib directory and then use it from your uploader by first loading the file:
and then including it in the class:
You need to add another field to your table to keep the extra info. If your picture is "avatar", you add "avatar_information" as a wide varchar field. It will then store size information for your image and various versions, as well as a content type. You then use "@user.avatar.image_width", "@user.avatar.thumb.image_height", etc. to get the size. It adds "image_width", "image_height", and "content_type" methods to all versions. It also works with nested versions.
It does require ImageMagick, specifically the "identify" command.
It would be a good upgrade to use MiniMagick or RMagick to get the size. It would also be nice for this to be turned into a gem. I just don't have time, but I am using this code on multiple web sites.
Hope that helps.