Last active
January 2, 2016 17:29
-
-
Save alexdean/8336781 to your computer and use it in GitHub Desktop.
resizing an image with rmagick
This file contains hidden or 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
| require 'RMagick' | |
| # http://www.imagemagick.org/RMagick/doc/comtasks.html#thumb | |
| original_filename = 'image.jpg' | |
| thumb_filename = 'thumb.jpg' | |
| orig = Magick::Image.read(original_filename).first | |
| rows, cols = [150, 150] | |
| thumb = orig | |
| # don't do a resize if original is already smaller than desired thumbnail size | |
| if orig.rows > rows || orig.columns > cols | |
| thumb = orig.resize_to_fill(rows, cols) | |
| end | |
| thumb.write(thumb_filename) # {self.quality = 80} | |
| thumb.destroy! if thumb != orig | |
| orig.destroy! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment