Skip to content
Browse files

Merge branch 'master' of https://github.com/carnesmedia/thumbkit

  • Loading branch information...
2 parents 9531ea8 + 52fde90 commit f74732198672d38a68ba19828075318df95cf2ef @adrianpike committed Jun 11, 2012
View
7 README.md
@@ -1,7 +1,7 @@
# Thumbkit
-Thumbkit makes thumbnails from a variety of media types.
-Thumbkit is designed to work with carrierwave but does not require it.
+Thumbkit provides a unified API for generating thumbnail images from image, audio, and text sources.
+It plays nicely with Carrierwave out of the box, but doesn't require it.
> it's like quicklook for carrierwave :)
>
@@ -59,10 +59,11 @@ On OS X:
### Text thumbnails
Thumbkit uses [MiniMagick](https://github.com/probablycorey/mini_magick) to
-render text files.
+render text files, and depends on both Ghostscript and ImageMagick
On OS X:
+ $ brew install ghostscript
$ brew install imagemagick
$ gem install mini_magick
View
6 lib/thumbkit.rb
@@ -29,7 +29,11 @@ def self.defaults
end
def self.defaults=(options)
- @defaults += options
+ @defaults = defaults + options
+ end
+
+ def self.reset_defaults!
+ @defaults = nil
end
def self.processors
View
2 lib/thumbkit/adapters.rb
@@ -1,3 +1,3 @@
module Thumbkit::Adapters
- autoload :CarrierWave, 'thumbkit/adapters/carrierwave'
+ autoload :CarrierWave, 'thumbkit/adapters/carrier_wave'
end
View
16 lib/thumbkit/adapters/carrierwave.rb → lib/thumbkit/adapters/carrier_wave.rb
@@ -20,8 +20,20 @@
# end
#
module Thumbkit::Adapters::CarrierWave
- def thumbkit(width, height, options = {})
- options.merge!(width: width, height: height)
+ def thumbkit_options(args)
+ {}.tap do |options|
+ if args.size > 1
+ width = args.shift
+ height = args.shift
+ options.merge!(width: width, height: height)
+ end
+
+ options.merge! args.fetch(0, {})
+ end
+ end
+
+ def thumbkit(*args)
+ options = thumbkit_options(args)
cache_stored_file! if !cached?
thumbkit = Thumbkit.new(current_path)
result = thumbkit.write_thumbnail(nil, options)
View
10 lib/thumbkit/processor.rb
@@ -48,7 +48,15 @@ def self.force_extension(filename, extension)
def initialize(path, outfile, options)
@path = path
@outfile = outfile || determine_outfile
- @options = Thumbkit.defaults + options
+ @options = default_options + options + options.fetch(processor_name, {})
+ end
+
+ def processor_name
+ self.class.name.split('::').last.to_sym
+ end
+
+ def default_options
+ Thumbkit.defaults + Thumbkit.defaults.fetch(processor_name, {})
end
def determine_outfile
View
2 lib/thumbkit/version.rb
@@ -1,3 +1,3 @@
class Thumbkit
- VERSION = "0.1.0"
+ VERSION = "0.1.3"
end
View
34 spec/thumbkit/adapters/carrier_wave_spec.rb
@@ -0,0 +1,34 @@
+require 'spec_helper'
+
+# TODO: Actually test carrierwave intergration somehow
+
+describe Thumbkit::Adapters::CarrierWave do
+ class TestUploader
+ include Thumbkit::Adapters::CarrierWave
+ end
+
+ describe '#thumbkit_options' do
+ subject { TestUploader.new.thumbkit_options options }
+
+ context 'given a width and a height' do
+ let(:options) { [10, 20] }
+ it { should == { width: 10, height: 20 } }
+ end
+
+ context 'given a width and a height and some options' do
+ let(:options) { [10, 20, { crop: false }] }
+ it { should == { width: 10, height: 20, crop: false } }
+ end
+
+ context 'given only some options' do
+ let(:options) { [{ crop: false }] }
+ it { should == { crop: false } }
+ end
+
+ context 'given nothing' do
+ let(:options) { [] }
+ it { should == {} }
+ end
+ end
+
+end
View
19 spec/thumbkit/processor/text_spec.rb
@@ -58,6 +58,25 @@
# Manually check the file to verify colors
end
+
+ context 'with size settings specifically for the text processor in defaults' do
+ let(:outfile) { path_for_output('text-test-300x250.png').to_s }
+ before { Thumbkit.defaults = { Text: { width: 300, height: 250 } } }
+ after { Thumbkit.reset_defaults! }
+
+ its_size_should_be('300x250')
+ its_mimetype_should_be('image/png')
+ end
+
+ context 'with size settings specifically for the text processor' do
+ let(:outfile) { path_for_output('text-test-300x250.png').to_s }
+ let(:options) { { Text: { width: 300, height: 250 } } }
+
+ its_size_should_be('300x250')
+ its_mimetype_should_be('image/png')
+ end
+
+
context 'with gravity settings' do
let(:outfile) { path_for_output('text-test-northeast-150x250.png').to_s }
# Let's change a few settings for manual inspection
View
32 spec/thumbkit/processor_spec.rb
@@ -44,4 +44,36 @@
end
end
end
+
+ describe '#default_options' do
+ subject { klass.new('infile.png', 'outfile.png', {}) }
+ context 'with some processor specific defaults' do
+ before do
+ Thumbkit.defaults = {
+ Text: { width: 10, colors: { background: '#111111' } },
+ Audio: { width: 20, colors: { background: '#222222' } },
+ }
+ end
+
+ context 'for the Text processor' do
+ let(:klass) { Thumbkit::Processor::Text }
+ it 'overrides the default options' do
+ subject.options[:width].should == 10
+ subject.options[:colors][:background].should == '#111111'
+ end
+ end
+
+
+ context 'for the Audio processor' do
+ let(:klass) { Thumbkit::Processor::Audio }
+ it 'overrides the default options' do
+ subject.options[:width].should == 20
+ subject.options[:colors][:background].should == '#222222'
+ end
+ end
+
+ end
+
+
+ end
end

0 comments on commit f747321

Please sign in to comment.
Something went wrong with that request. Please try again.