Skip to content

Instantly share code, notes, and snippets.

@amardaxini
Created February 2, 2011 14:50
Show Gist options
  • Save amardaxini/807784 to your computer and use it in GitHub Desktop.
Save amardaxini/807784 to your computer and use it in GitHub Desktop.
resize image using gd2 or generate thumbnail of image
require 'rubygems'
require 'gd2-ffij'
class Thumbnail
include GD2
def self.thumb(file_name,thumb_name,resized_width=100,resized_height=100,options={})
#import image
image = Image.import(file_name)
#resize image by passing width and height
resize_image = image.resize(resized_width, resized_height,true)
# export an image to desired file format
resize_image.export(thumb_name,options)
end
end
Thumbnail.thumb('test.jpg','thumb1.png',200,300)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment