Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/carnesmedia/thumbkit
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianpike committed Jun 5, 2012
2 parents d441711 + 2b40898 commit 9531ea8
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ you'll have to install them yourself.

Will write a 200x200 cropped image to `path/to/image.jpg`.

To get an image resized to fit instead of cropped:

```ruby
Thumbkit.new('path/to/image.jpg', crop: false).write_thumbnail
```

The format of the output file will depend on the extension of the output path
and defaults to the same as the input file.

Expand Down Expand Up @@ -203,6 +209,7 @@ All settings can be set globally. These are the defaults:
Thumbkit.defaults = {
width: 200, height: 200,
gravity: 'Center',
crop: true,
colors: { foreground: '#888888', background: '#eeeeee' },
font: {
family: 'Arial-Regular',
Expand Down
8 changes: 7 additions & 1 deletion lib/thumbkit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ def self.defaults
@defaults ||= Thumbkit::Options.new({
width: 200,
height: 200,
crop: true, # Whether or not we crop to fill the entire thumbnail size
# Whether or not we crop to fill the entire thumbnail size.
# Only affects images.
crop: true,
# Run `identify -list Gravity` for a list of available options
gravity: 'Center',
colors: {
Expand All @@ -26,6 +28,10 @@ def self.defaults
})
end

def self.defaults=(options)
@defaults += options
end

def self.processors
Thumbkit::Processor.processors
end
Expand Down
1 change: 1 addition & 0 deletions lib/thumbkit/processor/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def type

def resize_to_fit
image = ::MiniMagick::Image.open(path)
image.format type
image.resize "#{options[:width]}x#{options[:height]}"
image.write(outfile)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/thumbkit/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class Thumbkit
VERSION = "0.0.7"
VERSION = "0.1.0"
end
18 changes: 18 additions & 0 deletions spec/thumbkit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,21 @@
subject.should have_key(:font)
end
end


describe Thumbkit, '.defaults=' do
subject { Thumbkit.defaults }
before { Thumbkit.defaults = { font: { family: 'Helvetica' } } }

it 'still has all the other settings' do
subject.should have_key(:colors)
end

it 'still has the other default font settings' do
subject[:font].should have_key(:size)
end

it 'changes the font family' do
subject[:font][:family].should == 'Helvetica'
end
end

0 comments on commit 9531ea8

Please sign in to comment.