insano_image_resizer 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,144 @@
1
+ require 'spec_helper'
2
+
3
+ describe ImageResizer::Processor do
4
+
5
+ # IMPORTANT: Enable the flag below to print out the transforms that are generated by calculate_transform
6
+ # as you run the tests. This is great for updating the expected_results array below if you change the
7
+ # function and desire different behavior for the inputs, or add other test viewports of POIs.
8
+ actual_printed = false
9
+ actual_results = []
10
+
11
+ interest_variants_fractional = [{xf: 0, yf: 0}, {xf: 0, yf: 1}, {xf: 1, yf: 1}, {xf: 1, yf: 0}, {xf: 0.5, yf: 0.5}]
12
+ interest_variants_absolute = [{x: 0, y: 0}, {x: 0, y: 2500}, {x: 3800, y: 2500}, {x: 3800, y: 0}, {x: 3800.0 * 0.5, y: 2500.0 * 0.5}]
13
+ viewport_variants = [{w: 3800, h: 3000},
14
+ {w: 5000, h: 5000},
15
+ {w: 100, h: 100},
16
+ {w: 100, h: 300},
17
+ {w: 300, h: 100},
18
+ {w: 100},
19
+ {h: 100},
20
+ {w: 3000},
21
+ {h: 3000},
22
+ {}]
23
+
24
+ expected_abs_index = 0
25
+ expected_fraction_index = 0
26
+
27
+ expected_results = [{:x=>0.0, :y=>0.0, :w=>3800, :h=>3000, :scale=>1.2},
28
+ {:x=>0.0, :y=>0.0, :w=>5000, :h=>5000, :scale=>2.0},
29
+ {:x=>0.0, :y=>0.0, :w=>100, :h=>100, :scale=>0.04},
30
+ {:x=>0.0, :y=>0.0, :w=>100, :h=>300, :scale=>0.12},
31
+ {:x=>0.0, :y=>0.0, :w=>300, :h=>100, :scale=>0.07894736842105263},
32
+ {:x=>0.0, :y=>0.0, :w=>100, :h=>0, :scale=>0.02631578947368421},
33
+ {:x=>0.0, :y=>0.0, :w=>100, :h=>100, :scale=>0.04},
34
+ {:x=>0.0, :y=>0.0, :w=>3000, :h=>0, :scale=>0.7894736842105263},
35
+ {:x=>0.0, :y=>0.0, :w=>3000, :h=>3000, :scale=>1.2},
36
+ {:x=>0.0, :y=>0.0, :w=>3800, :h=>2500, :scale=>1.0},
37
+ {:x=>0.0, :y=>0.0, :w=>3800, :h=>3000, :scale=>1.2},
38
+ {:x=>0.0, :y=>0.0, :w=>5000, :h=>5000, :scale=>2.0},
39
+ {:x=>0.0, :y=>0.0, :w=>100, :h=>100, :scale=>0.04},
40
+ {:x=>0.0, :y=>0.0, :w=>100, :h=>300, :scale=>0.12},
41
+ {:x=>0.0, :y=>97.36842105263156, :w=>300, :h=>100, :scale=>0.07894736842105263},
42
+ {:x=>0.0, :y=>65.78947368421052, :w=>100, :h=>0, :scale=>0.02631578947368421},
43
+ {:x=>0.0, :y=>0.0, :w=>100, :h=>100, :scale=>0.04},
44
+ {:x=>0.0, :y=>1973.6842105263158, :w=>3000, :h=>0, :scale=>0.7894736842105263},
45
+ {:x=>0.0, :y=>0.0, :w=>3000, :h=>3000, :scale=>1.2},
46
+ {:x=>0.0, :y=>0.0, :w=>3800, :h=>2500, :scale=>1.0},
47
+ {:x=>760.0, :y=>0.0, :w=>3800, :h=>3000, :scale=>1.2},
48
+ {:x=>2600.0, :y=>0.0, :w=>5000, :h=>5000, :scale=>2.0},
49
+ {:x=>52.0, :y=>0.0, :w=>100, :h=>100, :scale=>0.04},
50
+ {:x=>356.0, :y=>0.0, :w=>100, :h=>300, :scale=>0.12},
51
+ {:x=>0.0, :y=>97.36842105263156, :w=>300, :h=>100, :scale=>0.07894736842105263},
52
+ {:x=>0.0, :y=>65.78947368421052, :w=>100, :h=>0, :scale=>0.02631578947368421},
53
+ {:x=>52.0, :y=>0.0, :w=>100, :h=>100, :scale=>0.04},
54
+ {:x=>0.0, :y=>1973.6842105263158, :w=>3000, :h=>0, :scale=>0.7894736842105263},
55
+ {:x=>1560.0, :y=>0.0, :w=>3000, :h=>3000, :scale=>1.2},
56
+ {:x=>0.0, :y=>0.0, :w=>3800, :h=>2500, :scale=>1.0},
57
+ {:x=>760.0, :y=>0.0, :w=>3800, :h=>3000, :scale=>1.2},
58
+ {:x=>2600.0, :y=>0.0, :w=>5000, :h=>5000, :scale=>2.0},
59
+ {:x=>52.0, :y=>0.0, :w=>100, :h=>100, :scale=>0.04},
60
+ {:x=>356.0, :y=>0.0, :w=>100, :h=>300, :scale=>0.12},
61
+ {:x=>0.0, :y=>0.0, :w=>300, :h=>100, :scale=>0.07894736842105263},
62
+ {:x=>0.0, :y=>0.0, :w=>100, :h=>0, :scale=>0.02631578947368421},
63
+ {:x=>52.0, :y=>0.0, :w=>100, :h=>100, :scale=>0.04},
64
+ {:x=>0.0, :y=>0.0, :w=>3000, :h=>0, :scale=>0.7894736842105263},
65
+ {:x=>1560.0, :y=>0.0, :w=>3000, :h=>3000, :scale=>1.2},
66
+ {:x=>0.0, :y=>0.0, :w=>3800, :h=>2500, :scale=>1.0},
67
+ {:x=>380.0, :y=>0.0, :w=>3800, :h=>3000, :scale=>1.2},
68
+ {:x=>1300.0, :y=>0.0, :w=>5000, :h=>5000, :scale=>2.0},
69
+ {:x=>26.0, :y=>0.0, :w=>100, :h=>100, :scale=>0.04},
70
+ {:x=>178.0, :y=>0.0, :w=>100, :h=>300, :scale=>0.12},
71
+ {:x=>0.0, :y=>48.68421052631578, :w=>300, :h=>100, :scale=>0.07894736842105263},
72
+ {:x=>0.0, :y=>32.89473684210526, :w=>100, :h=>0, :scale=>0.02631578947368421},
73
+ {:x=>26.0, :y=>0.0, :w=>100, :h=>100, :scale=>0.04},
74
+ {:x=>0.0, :y=>986.8421052631579, :w=>3000, :h=>0, :scale=>0.7894736842105263},
75
+ {:x=>780.0, :y=>0.0, :w=>3000, :h=>3000, :scale=>1.2},
76
+ {:x=>0.0, :y=>0.0, :w=>3800, :h=>2500, :scale=>1.0}]
77
+
78
+ before(:each) do
79
+ @source_jpg_path = SAMPLES_DIR.join('test.jpg') # 3872, 2592
80
+ @source_png_path = SAMPLES_DIR.join('test.png') # 177, 180
81
+ @source_jpg_props = {};
82
+ @source_jpg_props['width'] = 3800
83
+ @source_jpg_props['height'] = 2500
84
+ @source_jpg_props['bands'] = 3
85
+
86
+
87
+ @processor = ImageResizer::Processor.new
88
+ end
89
+
90
+ describe "fetch_image_properties" do
91
+
92
+ it "should return a hash of properties containing width and height" do
93
+ properties = @processor.fetch_image_properties(@source_jpg_path)
94
+ properties['width'].should == @source_jpg_props['width']
95
+ properties['height'].should == @source_jpg_props['height']
96
+ end
97
+
98
+ it "should return a hash of properties containing depth (JPG=3)" do
99
+ properties = @processor.fetch_image_properties(@source_jpg_path)
100
+ properties['bands'].should == 3
101
+ end
102
+
103
+ it "should return a hash of properties containing depth (PNG=4)" do
104
+ properties = @processor.fetch_image_properties(@source_png_path)
105
+ properties['bands'].should == 4
106
+ end
107
+
108
+ describe "calculate_transform" do
109
+
110
+ interest_variants_absolute.each do |ip|
111
+ viewport_variants.each do |viewport|
112
+
113
+ it "should produce the correct transform viewport: #{viewport}, point: #{ip}" do
114
+ transform = @processor.calculate_transform(@source_jpg_path, @source_jpg_props, viewport, ip)
115
+ transform.should == expected_results[expected_abs_index]
116
+ expected_abs_index += 1
117
+ end
118
+
119
+ end
120
+ end
121
+
122
+ interest_variants_fractional.each do |ip|
123
+ viewport_variants.each do |viewport|
124
+
125
+ it "should produce the correct transform viewport: #{viewport}, point: #{ip}" do
126
+ transform = @processor.calculate_transform(@source_jpg_path, @source_jpg_props, viewport, ip)
127
+
128
+ if (actual_printed == true)
129
+ actual_results.push(transform)
130
+ if (actual_results.size() == interest_variants_fractional.size() * viewport_variants.size() - 1)
131
+ print actual_results
132
+ end
133
+ end
134
+
135
+ transform.should == expected_results[expected_fraction_index]
136
+ expected_fraction_index += 1
137
+ end
138
+
139
+ end
140
+ end
141
+
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe ImageResizer::Shell do
4
+
5
+ include ImageResizer::Shell
6
+
7
+ it "should raise an error if the identify command isn't found" do
8
+ suppressing_stderr do
9
+ lambda{
10
+ run "non-existent-command"
11
+ }.should raise_error(ImageResizer::Shell::CommandFailed)
12
+ end
13
+ end
14
+
15
+ describe "escaping args" do
16
+ {
17
+ %q(hello) => %q('hello'),
18
+ %q("hello") => %q('hello'),
19
+ %q('hello') => %q('hello'),
20
+ %q(he\'llo) => %q('he'\''llo'),
21
+ %q('he'\''llo') => %q('he'\''llo'),
22
+ %q("he'llo") => %q('he'\''llo'),
23
+ %q(hel$(lo)) => %q('hel$(lo)'),
24
+ %q(hel\$(lo)) => %q('hel$(lo)'),
25
+ %q('hel\$(lo)') => %q('hel\$(lo)')
26
+ }.each do |args, escaped_args|
27
+ it "should escape #{args.inspect} -> #{escaped_args.inspect}" do
28
+ pending "not applicable to windows" if running_on_windows?
29
+ escape_args(args).should == escaped_args
30
+ end
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1,61 @@
1
+ require "rubygems"
2
+ require "bundler"
3
+ Bundler.setup(:default, :test)
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'rspec'
8
+ require 'image_resizer'
9
+ require 'fileutils'
10
+ require 'pry'
11
+ require 'pry-nav'
12
+ require 'pry-stack_explorer'
13
+
14
+ # Requires supporting files with custom matchers and macros, etc,
15
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
16
+
17
+ SAMPLES_DIR = Pathname.new(File.expand_path(File.dirname(__FILE__) + '/../samples')) unless defined?(SAMPLES_DIR)
18
+
19
+ def todo
20
+ raise "TODO"
21
+ end
22
+
23
+
24
+ # require 'logger'
25
+ # LOG_FILE = 'tmp/test.log' unless defined?(LOG_FILE)
26
+ # FileUtils.rm_rf(LOG_FILE)
27
+ # def mock_app(extra_stubs={})
28
+ # mock('app', {
29
+ # :datastore => mock('datastore', :store => 'some_uid', :retrieve => ["SOME_DATA", {}], :destroy => nil),
30
+ # :processor => mock('processor', :process => "SOME_PROCESSED_DATA"),
31
+ # :encoder => mock('encoder', :encode => "SOME_ENCODED_DATA"),
32
+ # :analyzer => mock('analyzer', :analyse => "some_result", :analysis_methods => Module.new),
33
+ # :generator => mock('generator', :generate => "SOME_GENERATED_DATA"),
34
+ # :log => Logger.new(LOG_FILE),
35
+ # :cache_duration => 10000,
36
+ # :job_definitions => Module.new
37
+ # }.merge(extra_stubs)
38
+ # )
39
+ # end
40
+
41
+ # def test_app
42
+ # time = Time.now
43
+ # app = ImageResizer::App.send(:new, "test_#{time.sec}_#{time.usec}".to_sym)
44
+ # app.log = Logger.new(LOG_FILE)
45
+ # app.datastore.root_path = 'tmp/file_data_store_test'
46
+ # app
47
+ # end
48
+
49
+ def suppressing_stderr
50
+ original_stderr = $stderr.dup
51
+ tempfile = Tempfile.new('stderr')
52
+ $stderr.reopen(tempfile) rescue
53
+ yield
54
+ ensure
55
+ tempfile.close!
56
+ $stderr.reopen(original_stderr)
57
+ end
58
+
59
+ def running_on_windows?
60
+ ENV['OS'] && ENV['OS'].downcase == 'windows_nt'
61
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: insano_image_resizer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ben Gotow
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: jeweler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: pry
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: pry-nav
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: pry-stack_explorer
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: ! "An image resizing gem that generates smaller versions of requested
95
+ \n images. Calls through to VIPS on the command line to perform
96
+ processing,\n and automatically handles cropping and scaling
97
+ the requested image, taking\n a point of interest into account
98
+ if requested."
99
+ email: ben@populr.me
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files:
103
+ - LICENSE
104
+ - README.md
105
+ files:
106
+ - .rspec
107
+ - .rvmrc
108
+ - Gemfile
109
+ - Gemfile.lock
110
+ - LICENSE
111
+ - README.md
112
+ - Rakefile
113
+ - VERSION
114
+ - lib/image_resizer.rb
115
+ - lib/image_resizer/configurable.rb
116
+ - lib/image_resizer/loggable.rb
117
+ - lib/image_resizer/processor.rb
118
+ - lib/image_resizer/shell.rb
119
+ - samples/explanation.png
120
+ - samples/test.jpg
121
+ - samples/test.png
122
+ - spec/image_resizer/configurable_spec.rb
123
+ - spec/image_resizer/loggable_spec.rb
124
+ - spec/image_resizer/processor_spec.rb
125
+ - spec/image_resizer/shell_spec.rb
126
+ - spec/spec_helper.rb
127
+ homepage: http://github.com/populr/insano_image_resizer
128
+ licenses:
129
+ - MIT
130
+ post_install_message:
131
+ rdoc_options: []
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ none: false
136
+ requirements:
137
+ - - ! '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubyforge_project:
148
+ rubygems_version: 1.8.24
149
+ signing_key:
150
+ specification_version: 3
151
+ summary: An image resizing gem that calls through to VIPS on the command line.
152
+ test_files: []