Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paperclip resize and crop to rectangle

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!

like image 903
Danny Avatar asked Jan 16 '12 06:01

Danny


2 Answers

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

like image 159
wyattisimo Avatar answered Oct 14 '22 22:10

wyattisimo


are any of these usefull?

Resize an image with Paperclip

Simple cropping with Paperclip

http://mfischer.com/wordpress/2009/02/02/multiple-image-upload-and-crop-with-rails/comment-page-1/

like image 1
dgasper Avatar answered Oct 14 '22 22:10

dgasper