I'm a big fan of attachment_fu, but one of the things that it doesn't do 'out-of-the-box' is allow you to specify a fixed width and height for a thumbnail so that you can create a cropped image. I spent a while digging around other sites and found some great tips from Toolman Tim regarding cropping images in attachment_fu using mini magick -- but what if you to stick with RMagick? In the model that is used for your uploaded images, just add a bang (!) to force a crop. Notice how the thumbnail type 'cropped' specifies height and width and contains a bang (!).
has_attachment :content_type => :image,
:storage => :s3,
:path_prefix => '/your_directory/',
:max_size => 500.kilobytes,
:resize_to => '400>',
:thumbnails => {
:regular_resize => '60',
:cropped => '50x50!' }# Performs the actual resizing operation for a thumbnail
def resize_image(img, size)
size = size.first if size.is_a?(Array) && size.length == 1 && !size.first.is_a?(Fixnum)
if size.is_a?(Fixnum) || (size.is_a?(Array) && size.first.is_a?(Fixnum))
size = [size, size] if size.is_a?(Fixnum)
img.crop_resized!(*size)
else
img.change_geometry(size.to_s) { |cols, rows, image| image.crop_resized!(cols, rows) }
end
self.temp_path = write_to_temp_file(img.to_blob)
end