Crop and resize an image using MiniMagick

During my dealings with twitter avatars (see here) I discovered how to resize and crop an image using MiniMagick. This is useful when dealing with twitter avatars as the large size ones that the twitter api provides are not always square and the smaller ones may be too small for some applications. Below is the simple function :

def resize_and_crop(image, size)         
  if image.width < image.height   
    remove = ((image.height - image.width)/2).round 
  elsif image.width > image.height 
    remove = ((image.width - image.height)/2).round
  return image

2 thoughts on “Crop and resize an image using MiniMagick

  1. Pingback: Crop and resize an image using MiniMagick (Ruby on Rails) : Max Ivak Personal Site

Leave a Reply

Your email address will not be published. Required fields are marked *