dragonfly 0.9.15 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of dragonfly might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/.gitignore +1 -8
- data/.travis.yml +11 -0
- data/Gemfile +1 -0
- data/History.md +52 -2
- data/LICENSE +1 -1
- data/README.md +38 -95
- data/dev/grid.jpg +0 -0
- data/dev/irbrc.rb +27 -0
- data/dev/rails_template.rb +38 -0
- data/dev/test.ru +56 -0
- data/dev/test_rails +19 -0
- data/dragonfly.gemspec +3 -21
- data/lib/dragonfly.rb +45 -44
- data/lib/dragonfly/app.rb +175 -96
- data/lib/dragonfly/configurable.rb +71 -170
- data/lib/dragonfly/content.rb +211 -0
- data/lib/dragonfly/core_ext/object.rb +1 -6
- data/lib/dragonfly/file_data_store.rb +197 -0
- data/lib/dragonfly/image_magick/analysers/image_properties.rb +23 -0
- data/lib/dragonfly/image_magick/generators/convert.rb +19 -0
- data/lib/dragonfly/image_magick/generators/plain.rb +26 -0
- data/lib/dragonfly/image_magick/generators/plasma.rb +25 -0
- data/lib/dragonfly/image_magick/generators/text.rb +127 -0
- data/lib/dragonfly/image_magick/plugin.rb +83 -0
- data/lib/dragonfly/image_magick/processors/convert.rb +29 -0
- data/lib/dragonfly/image_magick/processors/encode.rb +18 -0
- data/lib/dragonfly/image_magick/processors/thumb.rb +76 -0
- data/lib/dragonfly/job.rb +118 -134
- data/lib/dragonfly/job_endpoint.rb +2 -0
- data/lib/dragonfly/memory_data_store.rb +34 -0
- data/lib/dragonfly/middleware.rb +5 -3
- data/lib/dragonfly/{active_model_extensions.rb → model.rb} +5 -3
- data/lib/dragonfly/{active_model_extensions → model}/attachment.rb +40 -35
- data/lib/dragonfly/{active_model_extensions → model}/attachment_class_methods.rb +36 -40
- data/lib/dragonfly/model/class_methods.rb +109 -0
- data/lib/dragonfly/{active_model_extensions → model}/instance_methods.rb +2 -2
- data/lib/dragonfly/{active_model_extensions → model}/validations.rb +17 -12
- data/lib/dragonfly/railtie.rb +8 -6
- data/lib/dragonfly/register.rb +27 -0
- data/lib/dragonfly/response.rb +47 -52
- data/lib/dragonfly/routed_endpoint.rb +4 -0
- data/lib/dragonfly/serializer.rb +15 -5
- data/lib/dragonfly/server.rb +56 -29
- data/lib/dragonfly/shell.rb +12 -23
- data/lib/dragonfly/spec/data_store_examples.rb +64 -0
- data/lib/dragonfly/temp_object.rb +32 -47
- data/lib/dragonfly/url_attributes.rb +19 -22
- data/lib/dragonfly/url_mapper.rb +3 -0
- data/lib/dragonfly/utils.rb +12 -0
- data/lib/dragonfly/version.rb +1 -1
- data/lib/dragonfly/whitelist.rb +19 -0
- data/lib/rails/generators/dragonfly/USAGE +8 -0
- data/lib/rails/generators/dragonfly/dragonfly_generator.rb +24 -0
- data/lib/rails/generators/dragonfly/templates/initializer.rb.erb +27 -0
- data/samples/gif.gif +0 -0
- data/spec/dragonfly/app_spec.rb +270 -64
- data/spec/dragonfly/configurable_spec.rb +142 -418
- data/spec/dragonfly/content_spec.rb +353 -0
- data/spec/dragonfly/cookie_monster_spec.rb +2 -1
- data/spec/dragonfly/file_data_store_spec.rb +301 -0
- data/spec/dragonfly/image_magick/analysers/image_properties_spec.rb +20 -0
- data/spec/dragonfly/image_magick/generators/convert_spec.rb +19 -0
- data/spec/dragonfly/image_magick/generators/plain_spec.rb +50 -0
- data/spec/dragonfly/image_magick/generators/plasma_spec.rb +32 -0
- data/spec/dragonfly/image_magick/generators/text_spec.rb +77 -0
- data/spec/dragonfly/image_magick/plugin_spec.rb +131 -0
- data/spec/dragonfly/image_magick/processors/convert_spec.rb +56 -0
- data/spec/dragonfly/image_magick/processors/thumb_spec.rb +173 -0
- data/spec/dragonfly/job_endpoint_spec.rb +30 -73
- data/spec/dragonfly/job_spec.rb +280 -608
- data/spec/dragonfly/memory_data_store_spec.rb +20 -0
- data/spec/dragonfly/middleware_spec.rb +47 -27
- data/spec/dragonfly/{active_model_extensions → model}/model_spec.rb +331 -555
- data/spec/dragonfly/model/validations_spec.rb +196 -0
- data/spec/dragonfly/register_spec.rb +35 -0
- data/spec/dragonfly/routed_endpoint_spec.rb +6 -6
- data/spec/dragonfly/serializer_spec.rb +13 -15
- data/spec/dragonfly/server_spec.rb +122 -46
- data/spec/dragonfly/shell_spec.rb +43 -24
- data/spec/dragonfly/temp_object_spec.rb +69 -94
- data/spec/dragonfly/url_attributes_spec.rb +49 -0
- data/spec/dragonfly/utils_spec.rb +32 -0
- data/spec/dragonfly/whitelist_spec.rb +30 -0
- data/spec/dragonfly_spec.rb +43 -0
- data/spec/fixtures/deprecated_stored_content/eggs.bonus +1 -0
- data/spec/fixtures/deprecated_stored_content/eggs.bonus.meta +1 -0
- data/spec/functional/configuration_spec.rb +19 -0
- data/spec/functional/model_urls_spec.rb +43 -41
- data/spec/functional/remote_on_the_fly_spec.rb +14 -16
- data/spec/functional/shell_commands_spec.rb +24 -14
- data/spec/functional/to_response_spec.rb +10 -10
- data/spec/functional/urls_spec.rb +5 -3
- data/spec/spec_helper.rb +23 -28
- data/spec/support/argument_matchers.rb +7 -8
- data/spec/support/image_matchers.rb +14 -36
- data/spec/support/model_helpers.rb +97 -0
- data/spec/support/simple_matchers.rb +12 -0
- metadata +92 -393
- data/.yardopts +0 -29
- data/Rakefile +0 -36
- data/config.ru +0 -14
- data/docs.watchr +0 -1
- data/extra_docs/Analysers.md +0 -68
- data/extra_docs/Caching.md +0 -23
- data/extra_docs/Configuration.md +0 -149
- data/extra_docs/Couch.md +0 -49
- data/extra_docs/DataStorage.md +0 -226
- data/extra_docs/Encoding.md +0 -67
- data/extra_docs/ExampleUseCases.md +0 -116
- data/extra_docs/GeneralUsage.md +0 -105
- data/extra_docs/Generators.md +0 -68
- data/extra_docs/Heroku.md +0 -50
- data/extra_docs/ImageMagick.md +0 -136
- data/extra_docs/Index.md +0 -33
- data/extra_docs/MimeTypes.md +0 -40
- data/extra_docs/Models.md +0 -441
- data/extra_docs/Mongo.md +0 -42
- data/extra_docs/Processing.md +0 -77
- data/extra_docs/Rack.md +0 -52
- data/extra_docs/Rails2.md +0 -57
- data/extra_docs/Rails3.md +0 -56
- data/extra_docs/ServingRemotely.md +0 -104
- data/extra_docs/Sinatra.md +0 -25
- data/extra_docs/URLs.md +0 -203
- data/features/images.feature +0 -47
- data/features/no_processing.feature +0 -14
- data/features/rails.feature +0 -8
- data/features/steps/common_steps.rb +0 -8
- data/features/steps/dragonfly_steps.rb +0 -66
- data/features/steps/rails_steps.rb +0 -40
- data/features/support/env.rb +0 -13
- data/features/support/setup.rb +0 -41
- data/fixtures/rails/files/app/models/album.rb +0 -6
- data/fixtures/rails/files/app/views/albums/new.html.erb +0 -7
- data/fixtures/rails/files/app/views/albums/show.html.erb +0 -6
- data/fixtures/rails/files/config/initializers/dragonfly.rb +0 -4
- data/fixtures/rails/files/features/manage_album_images.feature +0 -38
- data/fixtures/rails/files/features/step_definitions/helper_steps.rb +0 -7
- data/fixtures/rails/files/features/step_definitions/image_steps.rb +0 -25
- data/fixtures/rails/files/features/step_definitions/web_steps.rb +0 -189
- data/fixtures/rails/files/features/support/paths.rb +0 -17
- data/fixtures/rails/files/features/text_images.feature +0 -7
- data/fixtures/rails/template.rb +0 -20
- data/irbrc.rb +0 -19
- data/lib/dragonfly/active_model_extensions/class_methods.rb +0 -98
- data/lib/dragonfly/analyser.rb +0 -58
- data/lib/dragonfly/analysis/file_command_analyser.rb +0 -33
- data/lib/dragonfly/analysis/image_magick_analyser.rb +0 -6
- data/lib/dragonfly/config/heroku.rb +0 -26
- data/lib/dragonfly/config/image_magick.rb +0 -6
- data/lib/dragonfly/config/rails.rb +0 -20
- data/lib/dragonfly/data_storage.rb +0 -11
- data/lib/dragonfly/data_storage/couch_data_store.rb +0 -83
- data/lib/dragonfly/data_storage/file_data_store.rb +0 -144
- data/lib/dragonfly/data_storage/mongo_data_store.rb +0 -96
- data/lib/dragonfly/data_storage/s3data_store.rb +0 -168
- data/lib/dragonfly/encoder.rb +0 -13
- data/lib/dragonfly/encoding/image_magick_encoder.rb +0 -6
- data/lib/dragonfly/function_manager.rb +0 -67
- data/lib/dragonfly/generation/image_magick_generator.rb +0 -6
- data/lib/dragonfly/generator.rb +0 -9
- data/lib/dragonfly/image_magick/analyser.rb +0 -53
- data/lib/dragonfly/image_magick/config.rb +0 -44
- data/lib/dragonfly/image_magick/encoder.rb +0 -57
- data/lib/dragonfly/image_magick/generator.rb +0 -147
- data/lib/dragonfly/image_magick/processor.rb +0 -114
- data/lib/dragonfly/image_magick/utils.rb +0 -46
- data/lib/dragonfly/image_magick_utils.rb +0 -4
- data/lib/dragonfly/job_builder.rb +0 -39
- data/lib/dragonfly/job_definitions.rb +0 -30
- data/lib/dragonfly/loggable.rb +0 -28
- data/lib/dragonfly/processing/image_magick_processor.rb +0 -6
- data/lib/dragonfly/processor.rb +0 -9
- data/lib/dragonfly/rails/images.rb +0 -32
- data/lib/dragonfly/simple_cache.rb +0 -23
- data/spec/dragonfly/active_model_extensions/spec_helper.rb +0 -95
- data/spec/dragonfly/analyser_spec.rb +0 -123
- data/spec/dragonfly/analysis/file_command_analyser_spec.rb +0 -49
- data/spec/dragonfly/data_storage/couch_data_store_spec.rb +0 -84
- data/spec/dragonfly/data_storage/file_data_store_spec.rb +0 -308
- data/spec/dragonfly/data_storage/mongo_data_store_spec.rb +0 -81
- data/spec/dragonfly/data_storage/s3_data_store_spec.rb +0 -277
- data/spec/dragonfly/data_storage/shared_data_store_examples.rb +0 -77
- data/spec/dragonfly/function_manager_spec.rb +0 -154
- data/spec/dragonfly/image_magick/analyser_spec.rb +0 -73
- data/spec/dragonfly/image_magick/encoder_spec.rb +0 -46
- data/spec/dragonfly/image_magick/generator_spec.rb +0 -178
- data/spec/dragonfly/image_magick/processor_spec.rb +0 -293
- data/spec/dragonfly/job_builder_spec.rb +0 -37
- data/spec/dragonfly/job_definitions_spec.rb +0 -57
- data/spec/dragonfly/loggable_spec.rb +0 -80
- data/spec/dragonfly/simple_cache_spec.rb +0 -27
- data/spec/dragonfly/url_attributes.rb +0 -47
- data/spec/functional/deprecations_spec.rb +0 -51
- data/spec/functional/image_magick_app_spec.rb +0 -27
- data/spec/test_imagemagick.ru +0 -49
- data/yard/handlers/configurable_attr_handler.rb +0 -38
- data/yard/setup.rb +0 -15
- data/yard/templates/default/fulldoc/html/css/common.css +0 -109
- data/yard/templates/default/layout/html/layout.erb +0 -93
- data/yard/templates/default/module/html/configuration_summary.erb +0 -31
- data/yard/templates/default/module/setup.rb +0 -17
@@ -1,73 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Dragonfly::ImageMagick::Analyser do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
@image = Dragonfly::TempObject.new(SAMPLES_DIR.join('beach.png'))
|
7
|
-
@analyser = Dragonfly::ImageMagick::Analyser.new
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should return the width" do
|
11
|
-
@analyser.width(@image).should == 280
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should return the height" do
|
15
|
-
@analyser.height(@image).should == 355
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should return the aspect ratio" do
|
19
|
-
@analyser.aspect_ratio(@image).should == (280.0/355.0)
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should say if it's portrait" do
|
23
|
-
@analyser.portrait?(@image).should be_true
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should say if it's landscape" do
|
27
|
-
@analyser.landscape?(@image).should be_false
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should return the number of colours" do
|
31
|
-
@analyser.number_of_colours(@image).should == 34703
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should return the depth" do
|
35
|
-
@analyser.depth(@image).should == 8
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should return the format" do
|
39
|
-
@analyser.format(@image).should == :png
|
40
|
-
end
|
41
|
-
|
42
|
-
%w(width height aspect_ratio number_of_colours depth format portrait? landscape?).each do |meth|
|
43
|
-
it "should throw unable_to_handle in #{meth.inspect} if it's not an image file" do
|
44
|
-
suppressing_stderr do
|
45
|
-
temp_object = Dragonfly::TempObject.new('blah')
|
46
|
-
lambda{
|
47
|
-
@analyser.send(meth, temp_object)
|
48
|
-
}.should throw_symbol(:unable_to_handle)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should say if it's an image" do
|
54
|
-
@analyser.image?(@image).should == true
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should say if it's not an image" do
|
58
|
-
suppressing_stderr do
|
59
|
-
@analyser.image?(Dragonfly::TempObject.new('blah')).should == false
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should work for images with spaces in the filename" do
|
64
|
-
image = Dragonfly::TempObject.new(SAMPLES_DIR.join('white pixel.png'))
|
65
|
-
@analyser.width(image).should == 1
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should work (width) for images with capital letter extensions" do
|
69
|
-
image = Dragonfly::TempObject.new(SAMPLES_DIR.join('DSC02119.JPG'))
|
70
|
-
@analyser.width(image).should == 1
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Dragonfly::ImageMagick::Encoder do
|
4
|
-
|
5
|
-
before(:all) do
|
6
|
-
sample_file = File.dirname(__FILE__) + '/../../../samples/beach.png' # 280x355, 135KB
|
7
|
-
@image = Dragonfly::TempObject.new(File.new(sample_file))
|
8
|
-
@encoder = Dragonfly::ImageMagick::Encoder.new
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "#encode" do
|
12
|
-
|
13
|
-
it "should encode the image to the correct format" do
|
14
|
-
image = @encoder.encode(@image, :gif)
|
15
|
-
image.should have_format('gif')
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should work with a string argument" do
|
19
|
-
image = @encoder.encode(@image, 'gif')
|
20
|
-
image.should have_format('gif')
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should throw :unable_to_handle if the format is not handleable" do
|
24
|
-
lambda{
|
25
|
-
@encoder.encode(@image, :goofy)
|
26
|
-
}.should throw_symbol(:unable_to_handle)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should do nothing if the image is already in the correct format" do
|
30
|
-
image = @encoder.encode(@image, :png)
|
31
|
-
image.should == @image
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should allow for extra args" do
|
35
|
-
image = @encoder.encode(@image, :jpg, '-quality 1')
|
36
|
-
image.should have_format('jpeg')
|
37
|
-
image.should have_size('1.45KB')
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should still work even if the image is already in the correct format and args are given" do
|
41
|
-
image = @encoder.encode(@image, :png, '-quality 1')
|
42
|
-
image.should_not == @image
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
@@ -1,178 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Dragonfly::ImageMagick::Generator do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
@generator = Dragonfly::ImageMagick::Generator.new
|
7
|
-
end
|
8
|
-
|
9
|
-
describe "plain" do
|
10
|
-
describe "of given dimensions and colour" do
|
11
|
-
before(:each) do
|
12
|
-
@image, @meta = @generator.plain(23,12,'white')
|
13
|
-
end
|
14
|
-
it {@image.should have_width(23)}
|
15
|
-
it {@image.should have_height(12)}
|
16
|
-
it {@image.should have_format('png')}
|
17
|
-
it {@meta.should == {:format => :png, :name => 'plain.png'}}
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should cope with colour name format" do
|
21
|
-
image, meta = @generator.plain(1, 1, 'red')
|
22
|
-
image.should have_width(1)
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should cope with rgb format" do
|
26
|
-
image, meta = @generator.plain(1, 1, 'rgb(244,255,1)')
|
27
|
-
image.should have_width(1)
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should cope with rgb percent format" do
|
31
|
-
image, meta = @generator.plain(1, 1, 'rgb(100%,50%,20%)')
|
32
|
-
image.should have_width(1)
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should cope with hex format" do
|
36
|
-
image, meta = @generator.plain(1, 1, '#fdafda')
|
37
|
-
image.should have_width(1)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should cope with uppercase hex format" do
|
41
|
-
image, meta = @generator.plain(1, 1, '#FDAFDA')
|
42
|
-
image.should have_width(1)
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should cope with shortened hex format" do
|
46
|
-
image, meta = @generator.plain(1, 1, '#fda')
|
47
|
-
image.should have_width(1)
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should cope with 'transparent'" do
|
51
|
-
image, meta = @generator.plain(1, 1, 'transparent')
|
52
|
-
image.should have_width(1)
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should cope with rgba format" do
|
56
|
-
image, meta = @generator.plain(1, 1, 'rgba(25,100,255,0.5)')
|
57
|
-
image.should have_width(1)
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should cope with hsl format" do
|
61
|
-
image, meta = @generator.plain(1, 1, 'hsl(25,100,255)')
|
62
|
-
image.should have_width(1)
|
63
|
-
end
|
64
|
-
|
65
|
-
describe "specifying the format" do
|
66
|
-
before(:each) do
|
67
|
-
@image, @meta = @generator.plain(23, 12, 'white', :format => :gif)
|
68
|
-
end
|
69
|
-
it {@image.should have_format('gif')}
|
70
|
-
it {@meta.should == {:format => :gif, :name => 'plain.gif'}}
|
71
|
-
end
|
72
|
-
|
73
|
-
it "works with string args" do
|
74
|
-
image, meta = @generator.plain(1, 1, 'white', 'format' => 'gif')
|
75
|
-
image.should have_format('gif')
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
describe "plasma" do
|
80
|
-
describe "of given dimensions" do
|
81
|
-
before(:each) do
|
82
|
-
@image, @meta = @generator.plasma(23,12)
|
83
|
-
end
|
84
|
-
it {@image.should have_width(23)}
|
85
|
-
it {@image.should have_height(12)}
|
86
|
-
it {@image.should have_format('png')}
|
87
|
-
it {@meta.should == {:format => :png, :name => 'plasma.png'}}
|
88
|
-
end
|
89
|
-
|
90
|
-
describe "specifying the format" do
|
91
|
-
before(:each) do
|
92
|
-
@image, @meta = @generator.plasma(23, 12, :gif)
|
93
|
-
end
|
94
|
-
it {@image.should have_format('gif')}
|
95
|
-
it {@meta.should == {:format => :gif, :name => 'plasma.gif'}}
|
96
|
-
end
|
97
|
-
|
98
|
-
it "works with string args" do
|
99
|
-
image, meta = @generator.plasma(1, 1, 'gif')
|
100
|
-
image.should have_format('gif')
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
describe "text" do
|
105
|
-
before(:each) do
|
106
|
-
@text = "mmm"
|
107
|
-
end
|
108
|
-
|
109
|
-
describe "creating a text image" do
|
110
|
-
before(:each) do
|
111
|
-
@image, @meta = @generator.text(@text, :font_size => 12)
|
112
|
-
end
|
113
|
-
it {@image.should have_width(20..40)} # approximate
|
114
|
-
it {@image.should have_height(10..20)}
|
115
|
-
it {@image.should have_format('png')}
|
116
|
-
it {@meta.should == {:format => :png, :name => 'text.png'}}
|
117
|
-
end
|
118
|
-
|
119
|
-
describe "specifying the format" do
|
120
|
-
before(:each) do
|
121
|
-
@image, @meta = @generator.text(@text, :format => :gif)
|
122
|
-
end
|
123
|
-
it {@image.should have_format('gif')}
|
124
|
-
it {@meta.should == {:format => :gif, :name => 'text.gif'}}
|
125
|
-
end
|
126
|
-
|
127
|
-
describe "padding" do
|
128
|
-
before(:each) do
|
129
|
-
no_padding_text, meta = @generator.text(@text, :font_size => 12)
|
130
|
-
@width = image_properties(no_padding_text)[:width].to_i
|
131
|
-
@height = image_properties(no_padding_text)[:height].to_i
|
132
|
-
end
|
133
|
-
it "1 number shortcut" do
|
134
|
-
image, meta = @generator.text(@text, :padding => '10')
|
135
|
-
image.should have_width(@width + 20)
|
136
|
-
image.should have_height(@height + 20)
|
137
|
-
end
|
138
|
-
it "2 numbers shortcut" do
|
139
|
-
image, meta = @generator.text(@text, :padding => '10 5')
|
140
|
-
image.should have_width(@width + 10)
|
141
|
-
image.should have_height(@height + 20)
|
142
|
-
end
|
143
|
-
it "3 numbers shortcut" do
|
144
|
-
image, meta = @generator.text(@text, :padding => '10 5 8')
|
145
|
-
image.should have_width(@width + 10)
|
146
|
-
image.should have_height(@height + 18)
|
147
|
-
end
|
148
|
-
it "4 numbers shortcut" do
|
149
|
-
image, meta = @generator.text(@text, :padding => '1 2 3 4')
|
150
|
-
image.should have_width(@width + 6)
|
151
|
-
image.should have_height(@height + 4)
|
152
|
-
end
|
153
|
-
it "should override the general padding declaration with the specific one (e.g. 'padding-left')" do
|
154
|
-
image, meta = @generator.text(@text, :padding => '10', 'padding-left' => 9)
|
155
|
-
image.should have_width(@width + 19)
|
156
|
-
image.should have_height(@height + 20)
|
157
|
-
end
|
158
|
-
it "should ignore 'px' suffixes" do
|
159
|
-
image, meta = @generator.text(@text, :padding => '1px 2px 3px 4px')
|
160
|
-
image.should have_width(@width + 6)
|
161
|
-
image.should have_height(@height + 4)
|
162
|
-
end
|
163
|
-
it "bad padding string" do
|
164
|
-
lambda{
|
165
|
-
@generator.text(@text, :padding => '1 2 3 4 5')
|
166
|
-
}.should raise_error(ArgumentError)
|
167
|
-
end
|
168
|
-
|
169
|
-
it "works with string args" do
|
170
|
-
image, meta = @generator.text(@text, 'format' => 'gif', 'padding' => '10')
|
171
|
-
image.should have_format('gif')
|
172
|
-
image.should have_width(@width + 20)
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
end
|
177
|
-
|
178
|
-
end
|
@@ -1,293 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Dragonfly::ImageMagick::Processor do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
@image = Dragonfly::TempObject.new(SAMPLES_DIR.join('beach.png')) # 280x355
|
7
|
-
@processor = Dragonfly::ImageMagick::Processor.new
|
8
|
-
end
|
9
|
-
|
10
|
-
describe "resize" do
|
11
|
-
|
12
|
-
it "should work correctly with xNN" do
|
13
|
-
image = @processor.resize(@image, 'x30')
|
14
|
-
image.should have_width(24)
|
15
|
-
image.should have_height(30)
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should work correctly with NNx" do
|
19
|
-
image = @processor.resize(@image, '30x')
|
20
|
-
image.should have_width(30)
|
21
|
-
image.should have_height(38)
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should work correctly with NNxNN" do
|
25
|
-
image = @processor.resize(@image, '30x30')
|
26
|
-
image.should have_width(24)
|
27
|
-
image.should have_height(30)
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should work correctly with NNxNN!" do
|
31
|
-
image = @processor.resize(@image, '30x30!')
|
32
|
-
image.should have_width(30)
|
33
|
-
image.should have_height(30)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should work correctly with NNxNN%" do
|
37
|
-
image = @processor.resize(@image, '25x50%')
|
38
|
-
image.should have_width(70)
|
39
|
-
image.should have_height(178)
|
40
|
-
end
|
41
|
-
|
42
|
-
describe "NNxNN>" do
|
43
|
-
|
44
|
-
it "should not resize if the image is smaller than specified" do
|
45
|
-
image = @processor.resize(@image, '1000x1000>')
|
46
|
-
image.should have_width(280)
|
47
|
-
image.should have_height(355)
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should resize if the image is larger than specified" do
|
51
|
-
image = @processor.resize(@image, '30x30>')
|
52
|
-
image.should have_width(24)
|
53
|
-
image.should have_height(30)
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
describe "NNxNN<" do
|
59
|
-
|
60
|
-
it "should not resize if the image is larger than specified" do
|
61
|
-
image = @processor.resize(@image, '10x10<')
|
62
|
-
image.should have_width(280)
|
63
|
-
image.should have_height(355)
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should resize if the image is smaller than specified" do
|
67
|
-
image = @processor.resize(@image, '400x400<')
|
68
|
-
image.should have_width(315)
|
69
|
-
image.should have_height(400)
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
end
|
75
|
-
|
76
|
-
describe "crop" do # Difficult to test here other than dimensions
|
77
|
-
|
78
|
-
it "should not crop if no args given" do
|
79
|
-
image = @processor.crop(@image)
|
80
|
-
image.should have_width(280)
|
81
|
-
image.should have_height(355)
|
82
|
-
end
|
83
|
-
|
84
|
-
it "should crop using the offset given" do
|
85
|
-
image = @processor.crop(@image, 'x' => '7', 'y' => '12')
|
86
|
-
image.should have_width(273)
|
87
|
-
image.should have_height(343)
|
88
|
-
end
|
89
|
-
|
90
|
-
it "should crop using the dimensions given" do
|
91
|
-
image = @processor.crop(@image, 'width' => '10', 'height' => '20')
|
92
|
-
image.should have_width(10)
|
93
|
-
image.should have_height(20)
|
94
|
-
end
|
95
|
-
|
96
|
-
it "should crop in one dimension if given" do
|
97
|
-
image = @processor.crop(@image, 'width' => '10')
|
98
|
-
image.should have_width(10)
|
99
|
-
image.should have_height(355)
|
100
|
-
end
|
101
|
-
|
102
|
-
it "should take into account the gravity given" do
|
103
|
-
image1 = @processor.crop(@image, 'width' => '10', 'height' => '10', 'gravity' => 'nw')
|
104
|
-
image2 = @processor.crop(@image, 'width' => '10', 'height' => '10', 'gravity' => 'se')
|
105
|
-
image1.should_not equal_image(image2)
|
106
|
-
end
|
107
|
-
|
108
|
-
it "should clip bits of the image outside of the requested crop area when not nw gravity" do
|
109
|
-
# Rmagick was previously throwing an error when the cropping area was outside the image size, when
|
110
|
-
# using a gravity other than nw
|
111
|
-
image = @processor.crop(@image, 'width' => '500', 'height' => '1000', 'x' => '100', 'y' => '200', 'gravity' => 'se')
|
112
|
-
image.should have_width(180)
|
113
|
-
image.should have_height(155)
|
114
|
-
end
|
115
|
-
|
116
|
-
it "should crop twice in a row correctly" do
|
117
|
-
image1 = @processor.crop(@image, 'x' => '10', 'y' => '10', 'width' => '100', 'height' => '100')
|
118
|
-
image2 = @processor.crop(Dragonfly::TempObject.new(image1), 'x' => '0' , 'y' => '0' , 'width' => '50' , 'height' => '50' )
|
119
|
-
image2.should have_width(50)
|
120
|
-
image2.should have_height(50)
|
121
|
-
end
|
122
|
-
|
123
|
-
it "should crop twice in a row while consciously keeping page geometry" do
|
124
|
-
# see http://www.imagemagick.org/Usage/crop/#crop_page
|
125
|
-
# it explains how cropping multiple times without resetting geometry behaves
|
126
|
-
image1 = @processor.crop(@image, 'x' => '10', 'y' => '10', 'width' => '100', 'height' => '100', 'repage' => false)
|
127
|
-
image2 = @processor.crop(Dragonfly::TempObject.new(image1), 'x' => '0' , 'y' => '0' , 'width' => '50' , 'height' => '50')
|
128
|
-
image2.should have_width(40)
|
129
|
-
image2.should have_height(40)
|
130
|
-
end
|
131
|
-
|
132
|
-
end
|
133
|
-
|
134
|
-
describe "greyscale" do
|
135
|
-
it "should not raise an error" do
|
136
|
-
# Bit tricky to test
|
137
|
-
@processor.greyscale(@image)
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
describe "resize_and_crop" do
|
142
|
-
|
143
|
-
it "should do nothing if no args given" do
|
144
|
-
image = @processor.resize_and_crop(@image)
|
145
|
-
image.should have_width(280)
|
146
|
-
image.should have_height(355)
|
147
|
-
end
|
148
|
-
|
149
|
-
it "should do nothing if called without width and height" do
|
150
|
-
image = @processor.resize_and_crop(@image)
|
151
|
-
image.should have_width(280)
|
152
|
-
image.should have_height(355)
|
153
|
-
image.should eq @image
|
154
|
-
end
|
155
|
-
|
156
|
-
it "should crop to the correct dimensions" do
|
157
|
-
image = @processor.resize_and_crop(@image, 'width' => '100', 'height' => '100')
|
158
|
-
image.should have_width(100)
|
159
|
-
image.should have_height(100)
|
160
|
-
end
|
161
|
-
|
162
|
-
it "should actually resize before cropping" do
|
163
|
-
image1 = @processor.resize_and_crop(@image, 'width' => '100', 'height' => '100')
|
164
|
-
image2 = @processor.crop(@image, 'width' => '100', 'height' => '100', 'gravity' => 'c')
|
165
|
-
image1.should_not equal_image(image2)
|
166
|
-
end
|
167
|
-
|
168
|
-
it "should allow cropping in one dimension" do
|
169
|
-
image = @processor.resize_and_crop(@image, 'width' => '100')
|
170
|
-
image.should have_width(100)
|
171
|
-
image.should have_height(355)
|
172
|
-
end
|
173
|
-
|
174
|
-
it "should take into account the gravity given" do
|
175
|
-
image1 = @processor.resize_and_crop(@image, 'width' => '10', 'height' => '10', 'gravity' => 'nw')
|
176
|
-
image2 = @processor.resize_and_crop(@image, 'width' => '10', 'height' => '10', 'gravity' => 'se')
|
177
|
-
image1.should_not equal_image(image2)
|
178
|
-
end
|
179
|
-
|
180
|
-
end
|
181
|
-
|
182
|
-
describe "rotate" do
|
183
|
-
|
184
|
-
it "should rotate by 90 degrees" do
|
185
|
-
image = @processor.rotate(@image, 90)
|
186
|
-
image.should have_width(355)
|
187
|
-
image.should have_height(280)
|
188
|
-
end
|
189
|
-
|
190
|
-
it "should not rotate given a larger height and the '>' qualifier" do
|
191
|
-
image = @processor.rotate(@image, 90, 'qualifier' => '>')
|
192
|
-
image.should have_width(280)
|
193
|
-
image.should have_height(355)
|
194
|
-
end
|
195
|
-
|
196
|
-
it "should rotate given a larger height and the '<' qualifier" do
|
197
|
-
image = @processor.rotate(@image, 90, 'qualifier' => '<')
|
198
|
-
image.should have_width(355)
|
199
|
-
image.should have_height(280)
|
200
|
-
end
|
201
|
-
|
202
|
-
end
|
203
|
-
|
204
|
-
describe "strip" do
|
205
|
-
it "should strip exif data" do
|
206
|
-
jpg = Dragonfly::TempObject.new(Pathname.new(File.dirname(__FILE__) + '/../../../samples/taj.jpg'))
|
207
|
-
image = @processor.strip(jpg)
|
208
|
-
image.should have_width(300)
|
209
|
-
image.should have_height(300)
|
210
|
-
image.size.should < jpg.size
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
describe "thumb" do
|
215
|
-
it "should call resize if the correct string given" do
|
216
|
-
@processor.should_receive(:resize).with(@image, '30x40').and_return(image = mock)
|
217
|
-
@processor.thumb(@image, '30x40').should == image
|
218
|
-
end
|
219
|
-
it "should call resize_and_crop if the correct string given" do
|
220
|
-
@processor.should_receive(:resize_and_crop).with(@image, 'width' => '30', 'height' => '40', 'gravity' => 'se').and_return(image = mock)
|
221
|
-
@processor.thumb(@image, '30x40#se').should == image
|
222
|
-
end
|
223
|
-
it "should call crop if x and y given" do
|
224
|
-
@processor.should_receive(:crop).with(@image, 'width' => '30', 'height' => '40', 'x' => '+10', 'y' => '+20', 'gravity' => nil).and_return(image = mock)
|
225
|
-
@processor.thumb(@image, '30x40+10+20').should == image
|
226
|
-
end
|
227
|
-
it "should call crop if just gravity given" do
|
228
|
-
@processor.should_receive(:crop).with(@image, 'width' => '30', 'height' => '40', 'x' => nil, 'y' => nil, 'gravity' => 'sw').and_return(image = mock)
|
229
|
-
@processor.thumb(@image, '30x40sw').should == image
|
230
|
-
end
|
231
|
-
it "should call crop if x, y and gravity given" do
|
232
|
-
@processor.should_receive(:crop).with(@image, 'width' => '30', 'height' => '40', 'x' => '-10', 'y' => '-20', 'gravity' => 'se').and_return(image = mock)
|
233
|
-
@processor.thumb(@image, '30x40-10-20se').should == image
|
234
|
-
end
|
235
|
-
it "should raise an argument error if an unrecognized string is given" do
|
236
|
-
lambda{ @processor.thumb(@image, '30x40#ne!') }.should raise_error(ArgumentError)
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
describe "auto-orient" do
|
241
|
-
it "should rotate an image according to exif information" do
|
242
|
-
@image = Dragonfly::TempObject.new(SAMPLES_DIR.join('beach.jpg'))
|
243
|
-
@image.should have_width(355)
|
244
|
-
@image.should have_height(280)
|
245
|
-
image = @processor.auto_orient(@image)
|
246
|
-
image.should have_width(280)
|
247
|
-
image.should have_height(355)
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
|
-
describe "flip" do
|
252
|
-
it "should flip the image, leaving the same dimensions" do
|
253
|
-
image = @processor.flip(@image)
|
254
|
-
image.should have_width(280)
|
255
|
-
image.should have_height(355)
|
256
|
-
end
|
257
|
-
end
|
258
|
-
|
259
|
-
describe "flop" do
|
260
|
-
it "should flop the image, leaving the same dimensions" do
|
261
|
-
image = @processor.flop(@image)
|
262
|
-
image.should have_width(280)
|
263
|
-
image.should have_height(355)
|
264
|
-
end
|
265
|
-
end
|
266
|
-
|
267
|
-
describe "convert" do
|
268
|
-
it "should allow for general convert commands" do
|
269
|
-
image = @processor.convert(@image, '-scale 56x71')
|
270
|
-
image.should have_width(56)
|
271
|
-
image.should have_height(71)
|
272
|
-
end
|
273
|
-
|
274
|
-
it "should allow for general convert commands with added format" do
|
275
|
-
image, extra = @processor.convert(@image, '-scale 56x71', 'gif')
|
276
|
-
image.should have_width(56)
|
277
|
-
image.should have_height(71)
|
278
|
-
image.should have_format('gif')
|
279
|
-
extra[:format].should == :gif
|
280
|
-
end
|
281
|
-
|
282
|
-
it "should work for commands with parenthesis" do
|
283
|
-
image = @processor.convert(@image, "\\( +clone -sparse-color Barycentric '0,0 black 0,%[fx:h-1] white' -function polynomial 2,-2,0.5 \\) -compose Blur -set option:compose:args 15 -composite")
|
284
|
-
image.should have_width(280)
|
285
|
-
end
|
286
|
-
|
287
|
-
it "should work for files with spaces in the name" do
|
288
|
-
image = Dragonfly::TempObject.new(SAMPLES_DIR.join('white pixel.png'))
|
289
|
-
@processor.convert(image, "-resize 2x2!").should have_width(2)
|
290
|
-
end
|
291
|
-
end
|
292
|
-
|
293
|
-
end
|