6

So I am expecting a series of photos of different sizes and aspect ratios. I want to be able to shrink/stretch the photo to fit as much as it can in a 200x100 rectangle and then crop the rest that does not fit. I want the crop to happen around the center as well. Is this possible? I am so confused with the imagemagick documentation.

Thanks!

Danny
  • 4,724
  • 6
  • 42
  • 55
  • I don't have a direct answer for you, but WordPress has some excellent Javascript image edit/crop tools in the Post-edit admin WYSIWYG editor that you might take a look at. – Peter Rowell Jan 16 '12 at 06:14

2 Answers2

19

Paperclip's # option will do exactly what you want: fit the image maximally within the specified dimensions then crop the excess with gravity at the center.

Example:

has_attached_file :photo,
                  :styles => {
                    :original => "200x100#"
                  }

Note: If you want to keep the original intact and generate an additional cropped thumb, just change the :original key to something else, like :thumb.

Reference: http://rdoc.info/github/thoughtbot/paperclip/Paperclip/ClassMethods

wyattisimo
  • 2,416
  • 2
  • 20
  • 18