thoughtbot/paperclip — pull request #835 by wireframe (2012-04-19 20:28:50+00:00)
Title: add Geometry#resize_to to calculate dimensions of new source

Here's an extension I've used in my application which seems like a good addition for the community at large.

Geometry#resize_to is an extension which allows you to take a geometry source and resize it to a destination ImageMagick geometry and calculate the appropriate destination width/height. It appropriately calculates the destination size for geometry with modifiers (ex: !, #, <, >) according to the appropriate ImageMagick rules.
http://www.imagemagick.org/Usage/resize/#resize

```ruby
Paperclip::Geometry.parse('256x256').resize_to('300x300>')
#=> 256x256
```

This is particularly helpful when using the original image dimensions are stored in order to calculate the size of the thumbnails (ex: setting the width/height attributes on an image tag).

```ruby
class User < ActiveRecord::Base
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }
after_post_process :save_file_dimensions
private
def save_file_dimensions
dimensions = Paperclip::Geometry.from_file(file.queued_for_write[:original])
self.avatar_width = dimensions.width
self.avatar_height = dimensions.height
end
end

u = User.create :avatar => File.new '/path/to/256x256.jpeg'
Paperclip::Geometry.new(u.avatar_width, u.avatar_height).resize_to u.styles[:medium].geometry
#=> 256x256
```