Thumbnail generator for Ruby applications.
First install ImageMagick then:
gem install thumbnail
or put this in Gemfile:
gem 'thumbnail', :git => 'git://github.com/christianhellsten/thumbnail.git'
Create a PNG thumbnail and cut the thumbnail to fit the given dimensions:
Thumbnail.create(
:in => 'test/images/image.jpg',
:out => 'tmp/images/image.png',
:width => 102,
:height => 103
)
Parameter | Description | Example |
---|---|---|
method | One of the supported methods of generating thumbnails, or your own method. | cut_to_fit, pad_to_fit |
in | Path of image | image.jpg |
out | Path of thumbnail | image.png, image.gif, image.jpg |
width | Width of thumbnail | 100 |
height | Height of thumbnail | 100 |
cmd | Path to “convert” command | /usr/bin/convert |
smush | Smush PNG or not? | Default is true |
Add your own thumbnail methods simply by defining them:
module Thumbnail
module Methods
class << self
def vignette(options)
%Q{-thumbnail #{options.width}x#{options.height}> \
-gravity #{options.gravity} \
-unsharp 0x.5 \
-alpha set \
-background none \
-vignette 0x4 \
-extent #{options.width}x#{options.height} \
-format png}
end
end
end
Then use them:
Thumbnail.create(
:method => :vignette,
:in => 'test/images/image.jpg',
:out => 'tmp/images/image.png',
:width => 102,
:height => 103
)
Read the ImageMagick documentation