Quantcast
Channel: Andrew's Blog » twitter
Viewing all articles
Browse latest Browse all 2

Crop and resize an image using MiniMagick

$
0
0

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 
    image.shave("0x#{remove}") 
  elsif image.width > image.height 
    remove = ((image.width - image.height)/2).round
    image.shave("#{remove}x0")
  end
  image.resize("#{size}x#{size}")
  return image
end

Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images