Include Rmagick in your source code. Be sure to place the include inside the class declaration.
require 'rmagick'
include Magick
Create a method like this
def thumb(source_image, geometry_string, radius = 10)
source_image.change_geometry(geometry_string) do |cols, rows, img|
thumb = img.resize(cols, rows)
mask = Image.new(cols, rows) {self.background_color = 'transparent'}
Draw.new.stroke('none').stroke_width(0).fill('white').
roundrectangle(0, 0, cols, rows, radius, radius).
draw(mask)
thumb.composite!(mask, 0, 0, Magick::CopyOpacityCompositeOp)
thumb
end
end
Call a method like this
source_image = Image.read('my-big-image.jpg').first
thumbnail_image = thumb(source_image, '64x64>', 8)
thumbnail_image.write('thumb.png')
, , , . , .
, , http://www.imagemagick.org/RMagick/doc/imusage.html#geometry