Skip to content

Instantly share code, notes, and snippets.

@kennx
Created September 20, 2012 08:22
Show Gist options
  • Save kennx/3754657 to your computer and use it in GitHub Desktop.
Save kennx/3754657 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment