Created
September 7, 2012 01:54
-
-
Save takuya-i/3662521 to your computer and use it in GitHub Desktop.
rails with Rmagick createing thumbnail image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Create squre thumbnail from bytedata by RMagick | |
def thumbnail(size=128) | |
image = Magick::Image.from_blob(self.binary_contents).shift | |
image_width = image.columns | |
image_height = image.rows | |
if image_width > image_height | |
crap_size = image_width -image_height # 正方形にするため、カットするpixcel数 | |
thumbnail = image.crop(crap_size /2, 0, image_width - crap_size , image_height).resize(size, size) | |
elsif(image_height > image_width) | |
crap_size = image_height - image_width | |
thumbnail = image.crop(0, crap_size /2, image_width , image_height - crap_size).resize(size, size) | |
else | |
thumbnail = image.resize(size, size) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment