dragonfly 0.7.7 → 0.8.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.

Files changed (67) hide show
  1. data/Gemfile +1 -1
  2. data/Gemfile.rails.2.3.5 +0 -1
  3. data/History.md +12 -0
  4. data/README.md +4 -2
  5. data/VERSION +1 -1
  6. data/config.ru +1 -1
  7. data/dragonfly.gemspec +256 -179
  8. data/extra_docs/Analysers.md +15 -6
  9. data/extra_docs/Configuration.md +13 -2
  10. data/extra_docs/Encoding.md +20 -7
  11. data/extra_docs/GeneralUsage.md +8 -5
  12. data/extra_docs/Generators.md +17 -7
  13. data/extra_docs/Heroku.md +1 -2
  14. data/extra_docs/MimeTypes.md +1 -1
  15. data/extra_docs/Models.md +1 -1
  16. data/extra_docs/Mongo.md +2 -2
  17. data/extra_docs/Processing.md +15 -7
  18. data/extra_docs/Rack.md +2 -3
  19. data/extra_docs/Rails2.md +2 -3
  20. data/extra_docs/Rails3.md +2 -3
  21. data/extra_docs/Sinatra.md +2 -2
  22. data/extra_docs/URLs.md +6 -4
  23. data/features/3.0.3.feature +8 -0
  24. data/features/steps/rails_steps.rb +2 -2
  25. data/features/support/env.rb +1 -1
  26. data/fixtures/files/app/views/albums/new.html.erb +4 -4
  27. data/fixtures/rails_2.3.5/template.rb +0 -1
  28. data/fixtures/{rails_3.0.0 → rails_3.0.3}/template.rb +0 -1
  29. data/irbrc.rb +1 -1
  30. data/lib/dragonfly/analysis/image_magick_analyser.rb +47 -0
  31. data/lib/dragonfly/app.rb +2 -0
  32. data/lib/dragonfly/config/image_magick.rb +41 -0
  33. data/lib/dragonfly/data_storage/file_data_store.rb +4 -2
  34. data/lib/dragonfly/data_storage/s3data_store.rb +7 -3
  35. data/lib/dragonfly/encoding/image_magick_encoder.rb +57 -0
  36. data/lib/dragonfly/generation/hash_with_css_style_keys.rb +23 -0
  37. data/lib/dragonfly/generation/image_magick_generator.rb +140 -0
  38. data/lib/dragonfly/generation/r_magick_generator.rb +0 -18
  39. data/lib/dragonfly/image_magick_utils.rb +81 -0
  40. data/lib/dragonfly/processing/image_magick_processor.rb +99 -0
  41. data/lib/dragonfly/rails/images.rb +1 -1
  42. data/lib/dragonfly/temp_object.rb +7 -6
  43. data/spec/dragonfly/analysis/image_magick_analyser_spec.rb +15 -0
  44. data/spec/dragonfly/analysis/r_magick_analyser_spec.rb +5 -49
  45. data/spec/dragonfly/analysis/shared_analyser_spec.rb +51 -0
  46. data/spec/dragonfly/app_spec.rb +2 -0
  47. data/spec/dragonfly/data_storage/data_store_spec.rb +6 -0
  48. data/spec/dragonfly/data_storage/file_data_store_spec.rb +1 -1
  49. data/spec/dragonfly/data_storage/s3_data_store_spec.rb +11 -1
  50. data/spec/dragonfly/deprecation_spec.rb +2 -2
  51. data/spec/dragonfly/encoding/image_magick_encoder_spec.rb +41 -0
  52. data/spec/dragonfly/encoding/r_magick_encoder_spec.rb +3 -6
  53. data/spec/dragonfly/generation/hash_with_css_style_keys_spec.rb +24 -0
  54. data/spec/dragonfly/generation/image_magick_generator_spec.rb +12 -0
  55. data/spec/dragonfly/generation/r_magick_generator_spec.rb +12 -123
  56. data/spec/dragonfly/generation/shared_generator_spec.rb +91 -0
  57. data/spec/dragonfly/image_magick_utils_spec.rb +16 -0
  58. data/spec/dragonfly/processing/image_magick_processor_spec.rb +29 -0
  59. data/spec/dragonfly/processing/r_magick_processor_spec.rb +2 -212
  60. data/spec/dragonfly/processing/shared_processing_spec.rb +215 -0
  61. data/spec/image_matchers.rb +6 -0
  62. data/spec/spec_helper.rb +11 -0
  63. data/yard/templates/default/fulldoc/html/css/common.css +9 -2
  64. data/yard/templates/default/layout/html/layout.erb +12 -1
  65. metadata +310 -11
  66. data/.gitignore +0 -15
  67. data/features/rails_3.0.0.feature +0 -8
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+ require 'dragonfly/generation/shared_generator_spec'
3
+
4
+ describe Dragonfly::Generation::ImageMagickGenerator do
5
+
6
+ before(:each) do
7
+ @generator = Dragonfly::Generation::ImageMagickGenerator.new
8
+ end
9
+
10
+ it_should_behave_like 'image generator'
11
+
12
+ end
@@ -1,135 +1,24 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ require 'spec_helper'
2
+ require 'dragonfly/generation/shared_generator_spec'
2
3
 
3
4
  describe Dragonfly::Generation::RMagickGenerator do
4
5
 
5
- describe "plasma" do
6
- before(:each) do
7
- @generator = Dragonfly::Generation::RMagickGenerator.new
8
- end
9
-
10
- describe "generating an image with the given dimensions" do
11
- before(:each) do
12
- @image, @extra = @generator.plasma(23,12)
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 {@extra.should == {:format => :png, :name => 'plasma.png'}}
18
- end
19
-
20
- describe "specifying the format" do
21
- before(:each) do
22
- @image, @extra = @generator.plasma(23, 12, :gif)
23
- end
24
- it {@image.should have_format('gif')}
25
- it {@extra.should == {:format => :gif, :name => 'plasma.gif'}}
26
- end
27
-
28
- describe "when not using the filesystem" do
29
- it "should still work" do
30
- @generator.use_filesystem = false
31
- image, extra = @generator.plasma(4, 6)
32
- image.should have_width(4)
33
- end
34
- end
6
+ before(:each) do
7
+ @generator = Dragonfly::Generation::RMagickGenerator.new
35
8
  end
36
9
 
37
- describe "text" do
10
+ describe "when using the filesystem" do
38
11
  before(:each) do
39
- @generator = Dragonfly::Generation::RMagickGenerator.new
40
- @text = "mmm"
41
- end
42
-
43
- describe "creating a text image" do
44
- before(:each) do
45
- @image, @extra = @generator.text(@text, :font_size => 12)
46
- end
47
- it {@image.should have_width(20..40)} # approximate
48
- it {@image.should have_height(10..20)}
49
- it {@image.should have_format('png')}
50
- it {@extra.should == {:format => :png, :name => 'text.png'}}
51
- end
52
-
53
- describe "specifying the format" do
54
- before(:each) do
55
- @image, @extra = @generator.text(@text, :format => :gif)
56
- end
57
- it {@image.should have_format('gif')}
58
- it {@extra.should == {:format => :gif, :name => 'text.gif'}}
59
- end
60
-
61
- describe "when not using the filesystem" do
62
- it "should still work" do
63
- @generator.use_filesystem = false
64
- image, extra = @generator.text(@text, :font_size => 12)
65
- image.should have_width(20..40)
66
- end
67
- end
68
-
69
- # it "should ignore percent characters used by rmagick"
70
-
71
- describe "padding" do
72
- before(:each) do
73
- no_padding_text, extra = @generator.text(@text, :font_size => 12)
74
- @width = image_properties(no_padding_text)[:width].to_i
75
- @height = image_properties(no_padding_text)[:height].to_i
76
- end
77
- it "1 number shortcut" do
78
- image, extra = @generator.text(@text, :padding => '10')
79
- image.should have_width(@width + 20)
80
- image.should have_height(@height + 20)
81
- end
82
- it "2 numbers shortcut" do
83
- image, extra = @generator.text(@text, :padding => '10 5')
84
- image.should have_width(@width + 10)
85
- image.should have_height(@height + 20)
86
- end
87
- it "3 numbers shortcut" do
88
- image, extra = @generator.text(@text, :padding => '10 5 8')
89
- image.should have_width(@width + 10)
90
- image.should have_height(@height + 18)
91
- end
92
- it "4 numbers shortcut" do
93
- image, extra = @generator.text(@text, :padding => '1 2 3 4')
94
- image.should have_width(@width + 6)
95
- image.should have_height(@height + 4)
96
- end
97
- it "should override the general padding declaration with the specific one (e.g. 'padding-left')" do
98
- image, extra = @generator.text(@text, :padding => '10', 'padding-left' => 9)
99
- image.should have_width(@width + 19)
100
- image.should have_height(@height + 20)
101
- end
102
- it "should ignore 'px' suffixes" do
103
- image, extra = @generator.text(@text, :padding => '1px 2px 3px 4px')
104
- image.should have_width(@width + 6)
105
- image.should have_height(@height + 4)
106
- end
107
- it "bad padding string" do
108
- lambda{
109
- @generator.text(@text, :padding => '1 2 3 4 5')
110
- }.should raise_error(ArgumentError)
111
- end
12
+ @generator.use_filesystem = true
112
13
  end
14
+ it_should_behave_like 'image generator'
113
15
  end
114
-
115
- describe Dragonfly::Generation::RMagickGenerator::HashWithCssStyleKeys do
16
+
17
+ describe "when not using the filesystem" do
116
18
  before(:each) do
117
- @hash = Dragonfly::Generation::RMagickGenerator::HashWithCssStyleKeys[
118
- :font_style => 'normal',
119
- :'font-weight' => 'bold',
120
- 'font_colour' => 'white',
121
- 'font-size' => 23,
122
- :hello => 'there'
123
- ]
124
- end
125
- describe "accessing using underscore symbol style" do
126
- it{ @hash[:font_style].should == 'normal' }
127
- it{ @hash[:font_weight].should == 'bold' }
128
- it{ @hash[:font_colour].should == 'white' }
129
- it{ @hash[:font_size].should == 23 }
130
- it{ @hash[:hello].should == 'there' }
131
- it{ @hash[:non_existent_key].should be_nil }
19
+ @generator.use_filesystem = false
132
20
  end
21
+ it_should_behave_like 'image generator'
133
22
  end
134
-
23
+
135
24
  end
@@ -0,0 +1,91 @@
1
+ require 'spec_helper'
2
+
3
+ # Needs: @generator
4
+ describe "image generator", :shared => true do
5
+
6
+ describe "generating an image with the given dimensions" do
7
+ before(:each) do
8
+ @image, @extra = @generator.plasma(23,12)
9
+ end
10
+ it {@image.should have_width(23)}
11
+ it {@image.should have_height(12)}
12
+ it {@image.should have_format('png')}
13
+ it {@extra.should == {:format => :png, :name => 'plasma.png'}}
14
+ end
15
+
16
+ describe "specifying the format" do
17
+ before(:each) do
18
+ @image, @extra = @generator.plasma(23, 12, :gif)
19
+ end
20
+ it {@image.should have_format('gif')}
21
+ it {@extra.should == {:format => :gif, :name => 'plasma.gif'}}
22
+ end
23
+
24
+ describe "text" do
25
+ before(:each) do
26
+ @text = "mmm"
27
+ end
28
+
29
+ describe "creating a text image" do
30
+ before(:each) do
31
+ @image, @extra = @generator.text(@text, :font_size => 12)
32
+ end
33
+ it {@image.should have_width(20..40)} # approximate
34
+ it {@image.should have_height(10..20)}
35
+ it {@image.should have_format('png')}
36
+ it {@extra.should == {:format => :png, :name => 'text.png'}}
37
+ end
38
+
39
+ describe "specifying the format" do
40
+ before(:each) do
41
+ @image, @extra = @generator.text(@text, :format => :gif)
42
+ end
43
+ it {@image.should have_format('gif')}
44
+ it {@extra.should == {:format => :gif, :name => 'text.gif'}}
45
+ end
46
+
47
+ describe "padding" do
48
+ before(:each) do
49
+ no_padding_text, extra = @generator.text(@text, :font_size => 12)
50
+ @width = image_properties(no_padding_text)[:width].to_i
51
+ @height = image_properties(no_padding_text)[:height].to_i
52
+ end
53
+ it "1 number shortcut" do
54
+ image, extra = @generator.text(@text, :padding => '10')
55
+ image.should have_width(@width + 20)
56
+ image.should have_height(@height + 20)
57
+ end
58
+ it "2 numbers shortcut" do
59
+ image, extra = @generator.text(@text, :padding => '10 5')
60
+ image.should have_width(@width + 10)
61
+ image.should have_height(@height + 20)
62
+ end
63
+ it "3 numbers shortcut" do
64
+ image, extra = @generator.text(@text, :padding => '10 5 8')
65
+ image.should have_width(@width + 10)
66
+ image.should have_height(@height + 18)
67
+ end
68
+ it "4 numbers shortcut" do
69
+ image, extra = @generator.text(@text, :padding => '1 2 3 4')
70
+ image.should have_width(@width + 6)
71
+ image.should have_height(@height + 4)
72
+ end
73
+ it "should override the general padding declaration with the specific one (e.g. 'padding-left')" do
74
+ image, extra = @generator.text(@text, :padding => '10', 'padding-left' => 9)
75
+ image.should have_width(@width + 19)
76
+ image.should have_height(@height + 20)
77
+ end
78
+ it "should ignore 'px' suffixes" do
79
+ image, extra = @generator.text(@text, :padding => '1px 2px 3px 4px')
80
+ image.should have_width(@width + 6)
81
+ image.should have_height(@height + 4)
82
+ end
83
+ it "bad padding string" do
84
+ lambda{
85
+ @generator.text(@text, :padding => '1 2 3 4 5')
86
+ }.should raise_error(ArgumentError)
87
+ end
88
+ end
89
+ end
90
+
91
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dragonfly::ImageMagickUtils do
4
+
5
+ before(:each) do
6
+ @obj = Object.new
7
+ @obj.extend(Dragonfly::ImageMagickUtils)
8
+ end
9
+
10
+ it "should raise an error if the identify command isn't found" do
11
+ lambda{
12
+ @obj.send(:run, "non-existent-command")
13
+ }.should raise_error(Dragonfly::ImageMagickUtils::ShellCommandFailed)
14
+ end
15
+
16
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+ require 'dragonfly/processing/shared_processing_spec'
3
+
4
+ describe Dragonfly::Processing::ImageMagickProcessor do
5
+
6
+ before(:each) do
7
+ sample_file = File.dirname(__FILE__) + '/../../../samples/beach.png' # 280x355
8
+ @image = Dragonfly::TempObject.new(File.new(sample_file))
9
+ @processor = Dragonfly::Processing::ImageMagickProcessor.new
10
+ end
11
+
12
+ it_should_behave_like "processing methods"
13
+
14
+ describe "convert" do
15
+ it "should allow for general convert commands" do
16
+ image = @processor.convert(@image, '-scale 56x71')
17
+ image.should have_width(56)
18
+ image.should have_height(71)
19
+ end
20
+ it "should allow for general convert commands with added format" do
21
+ image, extra = @processor.convert(@image, '-scale 56x71', :gif)
22
+ image.should have_width(56)
23
+ image.should have_height(71)
24
+ image.should have_format('gif')
25
+ extra[:format].should == :gif
26
+ end
27
+ end
28
+
29
+ end
@@ -1,218 +1,8 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ require 'spec_helper'
2
+ require 'dragonfly/processing/shared_processing_spec'
2
3
 
3
4
  describe Dragonfly::Processing::RMagickProcessor do
4
5
 
5
- describe "processing methods", :shared => true do
6
-
7
- describe "resize" do
8
-
9
- it "should work correctly with xNN" do
10
- image = @processor.resize(@image, 'x30')
11
- image.should have_width(24)
12
- image.should have_height(30)
13
- end
14
-
15
- it "should work correctly with NNx" do
16
- image = @processor.resize(@image, '30x')
17
- image.should have_width(30)
18
- image.should have_height(38)
19
- end
20
-
21
- it "should work correctly with NNxNN" do
22
- image = @processor.resize(@image, '30x30')
23
- image.should have_width(24)
24
- image.should have_height(30)
25
- end
26
-
27
- it "should work correctly with NNxNN!" do
28
- image = @processor.resize(@image, '30x30!')
29
- image.should have_width(30)
30
- image.should have_height(30)
31
- end
32
-
33
- it "should work correctly with NNxNN%" do
34
- image = @processor.resize(@image, '25x50%')
35
- image.should have_width(70)
36
- image.should have_height(178)
37
- end
38
-
39
- describe "NNxNN>" do
40
-
41
- it "should not resize if the image is smaller than specified" do
42
- image = @processor.resize(@image, '1000x1000>')
43
- image.should have_width(280)
44
- image.should have_height(355)
45
- end
46
-
47
- it "should resize if the image is larger than specified" do
48
- image = @processor.resize(@image, '30x30>')
49
- image.should have_width(24)
50
- image.should have_height(30)
51
- end
52
-
53
- end
54
-
55
- describe "NNxNN<" do
56
-
57
- it "should not resize if the image is larger than specified" do
58
- image = @processor.resize(@image, '10x10<')
59
- image.should have_width(280)
60
- image.should have_height(355)
61
- end
62
-
63
- it "should resize if the image is smaller than specified" do
64
- image = @processor.resize(@image, '400x400<')
65
- image.should have_width(315)
66
- image.should have_height(400)
67
- end
68
-
69
- end
70
-
71
- end
72
-
73
- describe "crop" do # Difficult to test here other than dimensions
74
-
75
- it "should not crop if no args given" do
76
- image = @processor.crop(@image)
77
- image.should have_width(280)
78
- image.should have_height(355)
79
- end
80
-
81
- it "should crop using the offset given" do
82
- image = @processor.crop(@image, :x => '7', :y => '12')
83
- image.should have_width(273)
84
- image.should have_height(343)
85
- end
86
-
87
- it "should crop using the dimensions given" do
88
- image = @processor.crop(@image, :width => '10', :height => '20')
89
- image.should have_width(10)
90
- image.should have_height(20)
91
- end
92
-
93
- it "should crop in one dimension if given" do
94
- image = @processor.crop(@image, :width => '10')
95
- image.should have_width(10)
96
- image.should have_height(355)
97
- end
98
-
99
- it "should take into account the gravity given" do
100
- image1 = @processor.crop(@image, :width => '10', :height => '10', :gravity => 'nw')
101
- image2 = @processor.crop(@image, :width => '10', :height => '10', :gravity => 'se')
102
- image1.should_not == image2
103
- end
104
-
105
- it "should clip bits of the image outside of the requested crop area when not nw gravity" do
106
- # Rmagick was previously throwing an error when the cropping area was outside the image size, when
107
- # using a gravity other than nw
108
- image = @processor.crop(@image, :width => '500', :height => '1000', :x => '100', :y => '200', :gravity => 'se')
109
- image.should have_width(180)
110
- image.should have_height(155)
111
- end
112
-
113
- end
114
-
115
- describe "greyscale" do
116
- it "should not raise an error" do
117
- # Bit tricky to test
118
- @processor.greyscale(@image)
119
- end
120
- end
121
-
122
- describe "resize_and_crop" do
123
-
124
- it "should do nothing if no args given" do
125
- image = @processor.resize_and_crop(@image)
126
- image.should have_width(280)
127
- image.should have_height(355)
128
- end
129
-
130
- it "should crop to the correct dimensions" do
131
- image = @processor.resize_and_crop(@image, :width => '100', :height => '100')
132
- image.should have_width(100)
133
- image.should have_height(100)
134
- end
135
-
136
- it "should allow cropping in one dimension" do
137
- image = @processor.resize_and_crop(@image, :width => '100')
138
- image.should have_width(100)
139
- image.should have_height(355)
140
- end
141
-
142
- it "should take into account the gravity given" do
143
- image1 = @processor.resize_and_crop(@image, :width => '10', :height => '10', :gravity => 'nw')
144
- image2 = @processor.resize_and_crop(@image, :width => '10', :height => '10', :gravity => 'se')
145
- image1.should_not == image2
146
- end
147
-
148
- end
149
-
150
- describe "rotate" do
151
-
152
- it "should rotate by 90 degrees" do
153
- image = @processor.rotate(@image, 90)
154
- image.should have_width(355)
155
- image.should have_height(280)
156
- end
157
-
158
- it "should not rotate given a larger height and the '>' qualifier" do
159
- image = @processor.rotate(@image, 90, :qualifier => '>')
160
- image.should have_width(280)
161
- image.should have_height(355)
162
- end
163
-
164
- it "should rotate given a larger height and the '<' qualifier" do
165
- image = @processor.rotate(@image, 90, :qualifier => '<')
166
- image.should have_width(355)
167
- image.should have_height(280)
168
- end
169
-
170
- end
171
-
172
- describe "thumb" do
173
- it "should call resize if the correct string given" do
174
- @processor.should_receive(:resize).with(@image, '30x40').and_return(image = mock)
175
- @processor.thumb(@image, '30x40').should == image
176
- end
177
- it "should call resize_and_crop if the correct string given" do
178
- @processor.should_receive(:resize_and_crop).with(@image, :width => '30', :height => '40', :gravity => 'se').and_return(image = mock)
179
- @processor.thumb(@image, '30x40#se').should == image
180
- end
181
- it "should call crop if x and y given" do
182
- @processor.should_receive(:crop).with(@image, :width => '30', :height => '40', :x => '+10', :y => '+20', :gravity => nil).and_return(image = mock)
183
- @processor.thumb(@image, '30x40+10+20').should == image
184
- end
185
- it "should call crop if just gravity given" do
186
- @processor.should_receive(:crop).with(@image, :width => '30', :height => '40', :x => nil, :y => nil, :gravity => 'sw').and_return(image = mock)
187
- @processor.thumb(@image, '30x40sw').should == image
188
- end
189
- it "should call crop if x, y and gravity given" do
190
- @processor.should_receive(:crop).with(@image, :width => '30', :height => '40', :x => '-10', :y => '-20', :gravity => 'se').and_return(image = mock)
191
- @processor.thumb(@image, '30x40-10-20se').should == image
192
- end
193
- it "should raise an argument error if an unrecognized string is given" do
194
- lambda{ @processor.thumb(@image, '30x40#ne!') }.should raise_error(ArgumentError)
195
- end
196
- end
197
-
198
- describe "flip" do
199
- it "should flip the image, leaving the same dimensions" do
200
- image = @processor.flip(@image)
201
- image.should have_width(280)
202
- image.should have_height(355)
203
- end
204
- end
205
-
206
- describe "flop" do
207
- it "should flop the image, leaving the same dimensions" do
208
- image = @processor.flop(@image)
209
- image.should have_width(280)
210
- image.should have_height(355)
211
- end
212
- end
213
-
214
- end
215
-
216
6
  before(:each) do
217
7
  sample_file = File.dirname(__FILE__) + '/../../../samples/beach.png' # 280x355
218
8
  @image = Dragonfly::TempObject.new(File.new(sample_file))