dragonfly 1.1.4 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +14 -6
- data/History.md +336 -309
- data/README.md +1 -1
- data/dev/rails_template.rb +35 -33
- data/dragonfly.gemspec +10 -16
- data/lib/dragonfly.rb +3 -1
- data/lib/dragonfly/content.rb +21 -22
- data/lib/dragonfly/image_magick/commands.rb +35 -0
- data/lib/dragonfly/image_magick/generators/plain.rb +13 -7
- data/lib/dragonfly/image_magick/generators/plasma.rb +10 -6
- data/lib/dragonfly/image_magick/generators/text.rb +67 -58
- data/lib/dragonfly/image_magick/plugin.rb +26 -25
- data/lib/dragonfly/image_magick/processors/encode.rb +16 -5
- data/lib/dragonfly/image_magick/processors/thumb.rb +37 -31
- data/lib/dragonfly/job/fetch_url.rb +1 -1
- data/lib/dragonfly/model/class_methods.rb +6 -1
- data/lib/dragonfly/param_validators.rb +37 -0
- data/lib/dragonfly/response.rb +2 -2
- data/lib/dragonfly/shell.rb +19 -13
- data/lib/dragonfly/utils.rb +1 -1
- data/lib/dragonfly/version.rb +1 -1
- data/samples/white pixel.png b/data/samples/mevs' white → pixel.png +0 -0
- data/spec/dragonfly/content_spec.rb +3 -3
- data/spec/dragonfly/cookie_monster_spec.rb +2 -2
- data/spec/dragonfly/image_magick/commands_spec.rb +98 -0
- data/spec/dragonfly/image_magick/generators/plain_spec.rb +39 -13
- data/spec/dragonfly/image_magick/generators/plasma_spec.rb +28 -9
- data/spec/dragonfly/image_magick/generators/text_spec.rb +51 -20
- data/spec/dragonfly/image_magick/plugin_spec.rb +45 -28
- data/spec/dragonfly/image_magick/processors/encode_spec.rb +30 -0
- data/spec/dragonfly/image_magick/processors/thumb_spec.rb +46 -45
- data/spec/dragonfly/model/active_record_spec.rb +62 -0
- data/spec/dragonfly/param_validators_spec.rb +89 -0
- data/spec/dragonfly/shell_spec.rb +12 -10
- data/spec/dragonfly_spec.rb +37 -13
- data/spec/functional/shell_commands_spec.rb +6 -9
- data/spec/spec_helper.rb +12 -14
- metadata +45 -14
- data/lib/dragonfly/image_magick/generators/convert.rb +0 -19
- data/lib/dragonfly/image_magick/processors/convert.rb +0 -33
- data/spec/dragonfly/image_magick/generators/convert_spec.rb +0 -19
- data/spec/dragonfly/image_magick/processors/convert_spec.rb +0 -88
@@ -1,4 +1,5 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
|
+
require "dragonfly/param_validators"
|
2
3
|
|
3
4
|
describe Dragonfly::ImageMagick::Generators::Plain do
|
4
5
|
let (:generator) { Dragonfly::ImageMagick::Generators::Plain.new }
|
@@ -9,32 +10,32 @@ describe Dragonfly::ImageMagick::Generators::Plain do
|
|
9
10
|
before(:each) do
|
10
11
|
generator.call(image, 3, 2)
|
11
12
|
end
|
12
|
-
it {image.should have_width(3)}
|
13
|
-
it {image.should have_height(2)}
|
14
|
-
it {image.should have_format(
|
15
|
-
it {image.meta.should == {
|
13
|
+
it { image.should have_width(3) }
|
14
|
+
it { image.should have_height(2) }
|
15
|
+
it { image.should have_format("png") }
|
16
|
+
it { image.meta.should == { "format" => "png", "name" => "plain.png" } }
|
16
17
|
end
|
17
18
|
|
18
19
|
describe "specifying the format" do
|
19
20
|
before(:each) do
|
20
|
-
generator.call(image, 1, 1,
|
21
|
+
generator.call(image, 1, 1, "format" => "gif")
|
21
22
|
end
|
22
|
-
it {image.should have_format(
|
23
|
-
it {image.meta.should == {
|
23
|
+
it { image.should have_format("gif") }
|
24
|
+
it { image.meta.should == { "format" => "gif", "name" => "plain.gif" } }
|
24
25
|
end
|
25
26
|
|
26
27
|
describe "specifying the colour" do
|
27
28
|
it "works with English spelling" do
|
28
|
-
generator.call(image, 1, 1,
|
29
|
+
generator.call(image, 1, 1, "colour" => "red")
|
29
30
|
end
|
30
31
|
|
31
32
|
it "works with American spelling" do
|
32
|
-
generator.call(image, 1, 1,
|
33
|
+
generator.call(image, 1, 1, "color" => "red")
|
33
34
|
end
|
34
35
|
|
35
36
|
it "blows up with a bad colour" do
|
36
37
|
expect {
|
37
|
-
generator.call(image, 1, 1,
|
38
|
+
generator.call(image, 1, 1, "colour" => "lardoin")
|
38
39
|
}.to raise_error(Dragonfly::Shell::CommandFailed)
|
39
40
|
end
|
40
41
|
end
|
@@ -42,9 +43,34 @@ describe Dragonfly::ImageMagick::Generators::Plain do
|
|
42
43
|
describe "urls" do
|
43
44
|
it "updates the url" do
|
44
45
|
url_attributes = Dragonfly::UrlAttributes.new
|
45
|
-
generator.update_url(url_attributes, 1, 1,
|
46
|
-
url_attributes.name.should ==
|
46
|
+
generator.update_url(url_attributes, 1, 1, "format" => "gif")
|
47
|
+
url_attributes.name.should == "plain.gif"
|
47
48
|
end
|
48
49
|
end
|
49
50
|
|
51
|
+
describe "param validations" do
|
52
|
+
{
|
53
|
+
"color" => "white -write bad.png",
|
54
|
+
"colour" => "white -write bad.png",
|
55
|
+
"format" => "png -write bad.png",
|
56
|
+
}.each do |opt, value|
|
57
|
+
it "validates bad opts like #{opt} = '#{value}'" do
|
58
|
+
expect {
|
59
|
+
generator.call(image, 1, 1, opt => value)
|
60
|
+
}.to raise_error(Dragonfly::ParamValidators::InvalidParameter)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
it "validates width" do
|
65
|
+
expect {
|
66
|
+
generator.call(image, "1 -write bad.png", 1)
|
67
|
+
}.to raise_error(Dragonfly::ParamValidators::InvalidParameter)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "validates height" do
|
71
|
+
expect {
|
72
|
+
generator.call(image, 1, "1 -write bad.png")
|
73
|
+
}.to raise_error(Dragonfly::ParamValidators::InvalidParameter)
|
74
|
+
end
|
75
|
+
end
|
50
76
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Dragonfly::ImageMagick::Generators::Plasma do
|
4
4
|
let (:generator) { Dragonfly::ImageMagick::Generators::Plasma.new }
|
@@ -10,23 +10,42 @@ describe Dragonfly::ImageMagick::Generators::Plasma do
|
|
10
10
|
generator.call(image, 5, 3)
|
11
11
|
image.should have_width(5)
|
12
12
|
image.should have_height(3)
|
13
|
-
image.should have_format(
|
14
|
-
image.meta.should == {
|
13
|
+
image.should have_format("png")
|
14
|
+
image.meta.should == { "format" => "png", "name" => "plasma.png" }
|
15
15
|
end
|
16
16
|
|
17
17
|
it "allows changing the format" do
|
18
|
-
generator.call(image, 1, 1,
|
19
|
-
image.should have_format(
|
20
|
-
image.meta.should == {
|
18
|
+
generator.call(image, 1, 1, "format" => "jpg")
|
19
|
+
image.should have_format("jpeg")
|
20
|
+
image.meta.should == { "format" => "jpg", "name" => "plasma.jpg" }
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
describe "urls" do
|
25
25
|
it "updates the url" do
|
26
26
|
url_attributes = Dragonfly::UrlAttributes.new
|
27
|
-
generator.update_url(url_attributes, 1, 1,
|
28
|
-
url_attributes.name.should ==
|
27
|
+
generator.update_url(url_attributes, 1, 1, "format" => "jpg")
|
28
|
+
url_attributes.name.should == "plasma.jpg"
|
29
29
|
end
|
30
30
|
end
|
31
|
-
end
|
32
31
|
|
32
|
+
describe "param validations" do
|
33
|
+
it "validates format" do
|
34
|
+
expect {
|
35
|
+
generator.call(image, 1, 1, "format" => "png -write bad.png")
|
36
|
+
}.to raise_error(Dragonfly::ParamValidators::InvalidParameter)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "validates width" do
|
40
|
+
expect {
|
41
|
+
generator.call(image, "1 -write bad.png", 1)
|
42
|
+
}.to raise_error(Dragonfly::ParamValidators::InvalidParameter)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "validates height" do
|
46
|
+
expect {
|
47
|
+
generator.call(image, 1, "1 -write bad.png")
|
48
|
+
}.to raise_error(Dragonfly::ParamValidators::InvalidParameter)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Dragonfly::ImageMagick::Generators::Text do
|
4
4
|
let (:generator) { Dragonfly::ImageMagick::Generators::Text.new }
|
@@ -7,62 +7,62 @@ describe Dragonfly::ImageMagick::Generators::Text do
|
|
7
7
|
|
8
8
|
describe "creating a text image" do
|
9
9
|
before(:each) do
|
10
|
-
generator.call(image, "mmm",
|
10
|
+
generator.call(image, "mmm", "font_size" => 12)
|
11
11
|
end
|
12
|
-
it {image.should have_width(20..40)} # approximate
|
13
|
-
it {image.should have_height(10..20)}
|
14
|
-
it {image.should have_format(
|
15
|
-
it {image.meta.should == {
|
12
|
+
it { image.should have_width(20..40) } # approximate
|
13
|
+
it { image.should have_height(10..20) }
|
14
|
+
it { image.should have_format("png") }
|
15
|
+
it { image.meta.should == { "format" => "png", "name" => "text.png" } }
|
16
16
|
end
|
17
17
|
|
18
18
|
describe "specifying the format" do
|
19
19
|
before(:each) do
|
20
|
-
generator.call(image, "mmm",
|
20
|
+
generator.call(image, "mmm", "format" => "gif")
|
21
21
|
end
|
22
|
-
it {image.should have_format(
|
23
|
-
it {image.meta.should == {
|
22
|
+
it { image.should have_format("gif") }
|
23
|
+
it { image.meta.should == { "format" => "gif", "name" => "text.gif" } }
|
24
24
|
end
|
25
25
|
|
26
26
|
describe "padding" do
|
27
27
|
before(:each) do
|
28
28
|
image_without_padding = image.clone
|
29
|
-
generator.call(image_without_padding, "mmm",
|
29
|
+
generator.call(image_without_padding, "mmm", "font_size" => 12)
|
30
30
|
@width = image_properties(image_without_padding)[:width].to_i
|
31
31
|
@height = image_properties(image_without_padding)[:height].to_i
|
32
32
|
end
|
33
33
|
it "1 number shortcut" do
|
34
|
-
generator.call(image, "mmm",
|
34
|
+
generator.call(image, "mmm", "padding" => "10")
|
35
35
|
image.should have_width(@width + 20)
|
36
36
|
image.should have_height(@height + 20)
|
37
37
|
end
|
38
38
|
it "2 numbers shortcut" do
|
39
|
-
generator.call(image, "mmm",
|
39
|
+
generator.call(image, "mmm", "padding" => "10 5")
|
40
40
|
image.should have_width(@width + 10)
|
41
41
|
image.should have_height(@height + 20)
|
42
42
|
end
|
43
43
|
it "3 numbers shortcut" do
|
44
|
-
generator.call(image, "mmm",
|
44
|
+
generator.call(image, "mmm", "padding" => "10 5 8")
|
45
45
|
image.should have_width(@width + 10)
|
46
46
|
image.should have_height(@height + 18)
|
47
47
|
end
|
48
48
|
it "4 numbers shortcut" do
|
49
|
-
generator.call(image, "mmm",
|
49
|
+
generator.call(image, "mmm", "padding" => "1 2 3 4")
|
50
50
|
image.should have_width(@width + 6)
|
51
51
|
image.should have_height(@height + 4)
|
52
52
|
end
|
53
53
|
it "should override the general padding declaration with the specific one (e.g. 'padding-left')" do
|
54
|
-
generator.call(image, "mmm",
|
54
|
+
generator.call(image, "mmm", "padding" => "10", "padding-left" => 9)
|
55
55
|
image.should have_width(@width + 19)
|
56
56
|
image.should have_height(@height + 20)
|
57
57
|
end
|
58
58
|
it "should ignore 'px' suffixes" do
|
59
|
-
generator.call(image, "mmm",
|
59
|
+
generator.call(image, "mmm", "padding" => "1px 2px 3px 4px")
|
60
60
|
image.should have_width(@width + 6)
|
61
61
|
image.should have_height(@height + 4)
|
62
62
|
end
|
63
63
|
it "bad padding string" do
|
64
|
-
lambda{
|
65
|
-
generator.call(image, "mmm",
|
64
|
+
lambda {
|
65
|
+
generator.call(image, "mmm", "padding" => "1 2 3 4 5")
|
66
66
|
}.should raise_error(ArgumentError)
|
67
67
|
end
|
68
68
|
end
|
@@ -70,8 +70,39 @@ describe Dragonfly::ImageMagick::Generators::Text do
|
|
70
70
|
describe "urls" do
|
71
71
|
it "updates the url" do
|
72
72
|
url_attributes = Dragonfly::UrlAttributes.new
|
73
|
-
generator.update_url(url_attributes, "mmm",
|
74
|
-
url_attributes.name.should ==
|
73
|
+
generator.update_url(url_attributes, "mmm", "format" => "gif")
|
74
|
+
url_attributes.name.should == "text.gif"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "param validations" do
|
79
|
+
{
|
80
|
+
"font" => "Times New Roman -write bad.png",
|
81
|
+
"font_family" => "Times New Roman -write bad.png",
|
82
|
+
"color" => "rgb(255, 34, 55) -write bad.png",
|
83
|
+
"background_color" => "rgb(255, 52, 55) -write bad.png",
|
84
|
+
"stroke_color" => "rgb(255, 52, 55) -write bad.png",
|
85
|
+
"format" => "png -write bad.png",
|
86
|
+
}.each do |opt, value|
|
87
|
+
it "validates bad opts like #{opt} = '#{value}'" do
|
88
|
+
expect {
|
89
|
+
generator.call(image, "some text", opt => value)
|
90
|
+
}.to raise_error(Dragonfly::ParamValidators::InvalidParameter)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
["rgb(33,33,33)", "rgba(33,33,33,0.5)", "rgb(33.5,33.5,33.5)", "#fff", "#efefef", "blue"].each do |colour|
|
95
|
+
it "allows #{colour.inspect} as a colour specification" do
|
96
|
+
generator.call(image, "mmm", "color" => colour)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
["rgb(33, 33, 33)", "something else", "blue:", "f#ff"].each do |colour|
|
101
|
+
it "disallows #{colour.inspect} as a colour specification" do
|
102
|
+
expect {
|
103
|
+
generator.call(image, "mmm", "color" => colour)
|
104
|
+
}.to raise_error(Dragonfly::ParamValidators::InvalidParameter)
|
105
|
+
end
|
75
106
|
end
|
76
107
|
end
|
77
108
|
end
|
@@ -1,25 +1,24 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe "a configured imagemagick app" do
|
4
|
-
|
5
|
-
let(:
|
6
|
-
let(:image){ app.fetch_file(SAMPLES_DIR.join('beach.png')) }
|
4
|
+
let(:app) { test_app.configure_with(:imagemagick) }
|
5
|
+
let(:image) { app.fetch_file(SAMPLES_DIR.join("beach.png")) }
|
7
6
|
|
8
7
|
describe "env variables" do
|
9
|
-
let(:app){ test_app }
|
8
|
+
let(:app) { test_app }
|
10
9
|
|
11
10
|
it "allows setting the convert command" do
|
12
11
|
app.configure do
|
13
|
-
plugin :imagemagick, :convert_command =>
|
12
|
+
plugin :imagemagick, :convert_command => "/bin/convert"
|
14
13
|
end
|
15
|
-
app.env[:convert_command].should ==
|
14
|
+
app.env[:convert_command].should == "/bin/convert"
|
16
15
|
end
|
17
16
|
|
18
17
|
it "allows setting the identify command" do
|
19
18
|
app.configure do
|
20
|
-
plugin :imagemagick, :identify_command =>
|
19
|
+
plugin :imagemagick, :identify_command => "/bin/identify"
|
21
20
|
end
|
22
|
-
app.env[:identify_command].should ==
|
21
|
+
app.env[:identify_command].should == "/bin/identify"
|
23
22
|
end
|
24
23
|
end
|
25
24
|
|
@@ -33,7 +32,7 @@ describe "a configured imagemagick app" do
|
|
33
32
|
end
|
34
33
|
|
35
34
|
it "should return the aspect ratio" do
|
36
|
-
image.aspect_ratio.should == (280.0/355.0)
|
35
|
+
image.aspect_ratio.should == (280.0 / 355.0)
|
37
36
|
end
|
38
37
|
|
39
38
|
it "should say if it's portrait" do
|
@@ -60,39 +59,39 @@ describe "a configured imagemagick app" do
|
|
60
59
|
end
|
61
60
|
|
62
61
|
it "should return false for pdfs" do
|
63
|
-
image.encode(
|
64
|
-
end
|
62
|
+
image.encode("pdf").image?.should be_falsey
|
63
|
+
end unless ENV["SKIP_FLAKY_TESTS"]
|
65
64
|
end
|
66
65
|
|
67
66
|
describe "processors that change the url" do
|
68
67
|
before do
|
69
|
-
app.configure{ url_format
|
68
|
+
app.configure { url_format "/:name" }
|
70
69
|
end
|
71
70
|
|
72
|
-
describe "
|
71
|
+
describe "thumb" do
|
73
72
|
it "sanity check with format" do
|
74
|
-
thumb = image.
|
73
|
+
thumb = image.thumb("1x1!", "format" => "jpg")
|
75
74
|
thumb.url.should =~ /^\/beach\.jpg\?.*job=\w+/
|
76
75
|
thumb.width.should == 1
|
77
|
-
thumb.format.should ==
|
78
|
-
thumb.meta[
|
76
|
+
thumb.format.should == "jpeg"
|
77
|
+
thumb.meta["format"].should == "jpg"
|
79
78
|
end
|
80
79
|
|
81
80
|
it "sanity check without format" do
|
82
|
-
thumb = image.
|
81
|
+
thumb = image.thumb("1x1!")
|
83
82
|
thumb.url.should =~ /^\/beach\.png\?.*job=\w+/
|
84
83
|
thumb.width.should == 1
|
85
|
-
thumb.format.should ==
|
86
|
-
thumb.meta[
|
84
|
+
thumb.format.should == "png"
|
85
|
+
thumb.meta["format"].should be_nil
|
87
86
|
end
|
88
87
|
end
|
89
88
|
|
90
89
|
describe "encode" do
|
91
90
|
it "sanity check" do
|
92
|
-
thumb = image.encode(
|
91
|
+
thumb = image.encode("jpg")
|
93
92
|
thumb.url.should =~ /^\/beach\.jpg\?.*job=\w+/
|
94
|
-
thumb.format.should ==
|
95
|
-
thumb.meta[
|
93
|
+
thumb.format.should == "jpeg"
|
94
|
+
thumb.meta["format"].should == "jpg"
|
96
95
|
end
|
97
96
|
end
|
98
97
|
end
|
@@ -100,13 +99,13 @@ describe "a configured imagemagick app" do
|
|
100
99
|
describe "other processors" do
|
101
100
|
describe "encode" do
|
102
101
|
it "should encode the image to the correct format" do
|
103
|
-
image.encode!(
|
104
|
-
image.format.should ==
|
102
|
+
image.encode!("gif")
|
103
|
+
image.format.should == "gif"
|
105
104
|
end
|
106
105
|
|
107
106
|
it "should allow for extra args" do
|
108
|
-
image.encode!(
|
109
|
-
image.format.should ==
|
107
|
+
image.encode!("jpg", "-quality 1")
|
108
|
+
image.format.should == "jpeg"
|
110
109
|
image.size.should < 2000
|
111
110
|
end
|
112
111
|
end
|
@@ -117,8 +116,13 @@ describe "a configured imagemagick app" do
|
|
117
116
|
image.width.should == 355
|
118
117
|
image.height.should == 280
|
119
118
|
end
|
120
|
-
end
|
121
119
|
|
120
|
+
it "disallows bad parameters" do
|
121
|
+
expect {
|
122
|
+
image.rotate!("90 -write bad.png").apply
|
123
|
+
}.to raise_error(Dragonfly::ParamValidators::InvalidParameter)
|
124
|
+
end
|
125
|
+
end
|
122
126
|
end
|
123
127
|
|
124
128
|
describe "identify" do
|
@@ -128,4 +132,17 @@ describe "a configured imagemagick app" do
|
|
128
132
|
end
|
129
133
|
end
|
130
134
|
|
135
|
+
describe "deprecated convert commands" do
|
136
|
+
it "raises a deprecated message if using the convert processor" do
|
137
|
+
expect {
|
138
|
+
image.convert!("into something").apply
|
139
|
+
}.to raise_error(/deprecated/i)
|
140
|
+
end
|
141
|
+
|
142
|
+
it "raises a deprecated message if using the convert generator" do
|
143
|
+
expect {
|
144
|
+
image.generate!(:convert, "into something").apply
|
145
|
+
}.to raise_error(/deprecated/i)
|
146
|
+
end
|
147
|
+
end
|
131
148
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Dragonfly::ImageMagick::Processors::Encode do
|
4
|
+
let (:app) { test_imagemagick_app }
|
5
|
+
let (:image) { Dragonfly::Content.new(app, SAMPLES_DIR.join("beach.png")) } # 280x355
|
6
|
+
let (:processor) { Dragonfly::ImageMagick::Processors::Encode.new }
|
7
|
+
|
8
|
+
it "encodes to a different format" do
|
9
|
+
processor.call(image, "jpeg")
|
10
|
+
image.should have_format("jpeg")
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "param validations" do
|
14
|
+
it "validates the format param" do
|
15
|
+
expect {
|
16
|
+
processor.call(image, "jpeg -write bad.png")
|
17
|
+
}.to raise_error(Dragonfly::ParamValidators::InvalidParameter)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "allows good args" do
|
21
|
+
processor.call(image, "jpeg", "-quality 10")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "disallows bad args" do
|
25
|
+
expect {
|
26
|
+
processor.call(image, "jpeg", "-write bad.png")
|
27
|
+
}.to raise_error(Dragonfly::ParamValidators::InvalidParameter)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -1,88 +1,80 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "spec_helper"
|
2
|
+
require "ostruct"
|
3
3
|
|
4
4
|
describe Dragonfly::ImageMagick::Processors::Thumb do
|
5
|
-
|
6
5
|
let (:app) { test_imagemagick_app }
|
7
|
-
let (:image) { Dragonfly::Content.new(app, SAMPLES_DIR.join(
|
6
|
+
let (:image) { Dragonfly::Content.new(app, SAMPLES_DIR.join("beach.png")) } # 280x355
|
8
7
|
let (:processor) { Dragonfly::ImageMagick::Processors::Thumb.new }
|
9
8
|
|
10
9
|
it "raises an error if an unrecognized string is given" do
|
11
|
-
expect{
|
12
|
-
processor.call(image,
|
10
|
+
expect {
|
11
|
+
processor.call(image, "30x40#ne!")
|
13
12
|
}.to raise_error(ArgumentError)
|
14
13
|
end
|
15
14
|
|
16
15
|
describe "resizing" do
|
17
|
-
|
18
16
|
it "works with xNN" do
|
19
|
-
processor.call(image,
|
17
|
+
processor.call(image, "x30")
|
20
18
|
image.should have_width(24)
|
21
19
|
image.should have_height(30)
|
22
20
|
end
|
23
21
|
|
24
22
|
it "works with NNx" do
|
25
|
-
processor.call(image,
|
23
|
+
processor.call(image, "30x")
|
26
24
|
image.should have_width(30)
|
27
25
|
image.should have_height(38)
|
28
26
|
end
|
29
27
|
|
30
28
|
it "works with NNxNN" do
|
31
|
-
processor.call(image,
|
29
|
+
processor.call(image, "30x30")
|
32
30
|
image.should have_width(24)
|
33
31
|
image.should have_height(30)
|
34
32
|
end
|
35
33
|
|
36
34
|
it "works with NNxNN!" do
|
37
|
-
processor.call(image,
|
35
|
+
processor.call(image, "30x30!")
|
38
36
|
image.should have_width(30)
|
39
37
|
image.should have_height(30)
|
40
38
|
end
|
41
39
|
|
42
40
|
it "works with NNxNN%" do
|
43
|
-
processor.call(image,
|
41
|
+
processor.call(image, "25x50%")
|
44
42
|
image.should have_width(70)
|
45
43
|
image.should have_height(178)
|
46
44
|
end
|
47
45
|
|
48
46
|
describe "NNxNN>" do
|
49
|
-
|
50
47
|
it "doesn't resize if the image is smaller than specified" do
|
51
|
-
processor.call(image,
|
48
|
+
processor.call(image, "1000x1000>")
|
52
49
|
image.should have_width(280)
|
53
50
|
image.should have_height(355)
|
54
51
|
end
|
55
52
|
|
56
53
|
it "resizes if the image is larger than specified" do
|
57
|
-
processor.call(image,
|
54
|
+
processor.call(image, "30x30>")
|
58
55
|
image.should have_width(24)
|
59
56
|
image.should have_height(30)
|
60
57
|
end
|
61
|
-
|
62
58
|
end
|
63
59
|
|
64
60
|
describe "NNxNN<" do
|
65
|
-
|
66
61
|
it "doesn't resize if the image is larger than specified" do
|
67
|
-
processor.call(image,
|
62
|
+
processor.call(image, "10x10<")
|
68
63
|
image.should have_width(280)
|
69
64
|
image.should have_height(355)
|
70
65
|
end
|
71
66
|
|
72
67
|
it "resizes if the image is smaller than specified" do
|
73
|
-
processor.call(image,
|
68
|
+
processor.call(image, "400x400<")
|
74
69
|
image.should have_width(315)
|
75
70
|
image.should have_height(400)
|
76
71
|
end
|
77
|
-
|
78
72
|
end
|
79
|
-
|
80
73
|
end
|
81
74
|
|
82
75
|
describe "cropping" do # Difficult to test here other than dimensions
|
83
|
-
|
84
76
|
it "crops" do
|
85
|
-
processor.call(image,
|
77
|
+
processor.call(image, "10x20+30+30")
|
86
78
|
image.should have_width(10)
|
87
79
|
image.should have_height(20)
|
88
80
|
end
|
@@ -90,11 +82,11 @@ describe Dragonfly::ImageMagick::Processors::Thumb do
|
|
90
82
|
it "crops with gravity" do
|
91
83
|
image2 = image.clone
|
92
84
|
|
93
|
-
processor.call(image,
|
85
|
+
processor.call(image, "10x8nw")
|
94
86
|
image.should have_width(10)
|
95
87
|
image.should have_height(8)
|
96
88
|
|
97
|
-
processor.call(image2,
|
89
|
+
processor.call(image2, "10x8se")
|
98
90
|
image2.should have_width(10)
|
99
91
|
image2.should have_height(8)
|
100
92
|
|
@@ -103,77 +95,86 @@ describe Dragonfly::ImageMagick::Processors::Thumb do
|
|
103
95
|
|
104
96
|
it "raises if given both gravity and offset" do
|
105
97
|
expect {
|
106
|
-
processor.call(image,
|
98
|
+
processor.call(image, "100x100+10+10se")
|
107
99
|
}.to raise_error(ArgumentError)
|
108
100
|
end
|
109
101
|
|
110
102
|
it "works when the crop area is outside the image" do
|
111
|
-
processor.call(image,
|
103
|
+
processor.call(image, "100x100+250+300")
|
112
104
|
image.should have_width(30)
|
113
105
|
image.should have_height(55)
|
114
106
|
end
|
115
107
|
|
116
108
|
it "crops twice in a row correctly" do
|
117
|
-
processor.call(image,
|
118
|
-
processor.call(image,
|
109
|
+
processor.call(image, "100x100+10+10")
|
110
|
+
processor.call(image, "50x50+0+0")
|
119
111
|
image.should have_width(50)
|
120
112
|
image.should have_height(50)
|
121
113
|
end
|
122
|
-
|
123
114
|
end
|
124
115
|
|
125
116
|
describe "resize_and_crop" do
|
126
|
-
|
127
117
|
it "crops to the correct dimensions" do
|
128
|
-
processor.call(image,
|
118
|
+
processor.call(image, "100x100#")
|
129
119
|
image.should have_width(100)
|
130
120
|
image.should have_height(100)
|
131
121
|
end
|
132
122
|
|
133
123
|
it "resizes before cropping" do
|
134
124
|
image2 = image.clone
|
135
|
-
processor.call(image,
|
136
|
-
processor.call(image2,
|
125
|
+
processor.call(image, "100x100#")
|
126
|
+
processor.call(image2, "100x100c")
|
137
127
|
image2.should_not equal_image(image)
|
138
128
|
end
|
139
129
|
|
140
130
|
it "works with gravity" do
|
141
131
|
image2 = image.clone
|
142
|
-
processor.call(image,
|
143
|
-
processor.call(image,
|
132
|
+
processor.call(image, "10x10#nw")
|
133
|
+
processor.call(image, "10x10#se")
|
144
134
|
image2.should_not equal_image(image)
|
145
135
|
end
|
146
|
-
|
147
136
|
end
|
148
137
|
|
149
138
|
describe "format" do
|
150
139
|
let (:url_attributes) { OpenStruct.new }
|
151
140
|
|
152
141
|
it "changes the format if passed in" do
|
153
|
-
processor.call(image,
|
154
|
-
image.should have_format(
|
142
|
+
processor.call(image, "2x2", "format" => "jpeg")
|
143
|
+
image.should have_format("jpeg")
|
155
144
|
end
|
156
145
|
|
157
146
|
it "doesn't change the format if not passed in" do
|
158
|
-
processor.call(image,
|
159
|
-
image.should have_format(
|
147
|
+
processor.call(image, "2x2")
|
148
|
+
image.should have_format("png")
|
160
149
|
end
|
161
150
|
|
162
151
|
it "updates the url ext if passed in" do
|
163
|
-
processor.update_url(url_attributes,
|
164
|
-
url_attributes.ext.should ==
|
152
|
+
processor.update_url(url_attributes, "2x2", "format" => "png")
|
153
|
+
url_attributes.ext.should == "png"
|
165
154
|
end
|
166
155
|
|
167
156
|
it "doesn't update the url ext if not passed in" do
|
168
|
-
processor.update_url(url_attributes,
|
157
|
+
processor.update_url(url_attributes, "2x2")
|
169
158
|
url_attributes.ext.should be_nil
|
170
159
|
end
|
171
160
|
end
|
172
161
|
|
173
162
|
describe "args_for_geometry" do
|
174
163
|
it "returns the convert arguments used for a given geometry" do
|
175
|
-
expect(processor.args_for_geometry(
|
164
|
+
expect(processor.args_for_geometry("30x40")).to eq("-resize 30x40")
|
176
165
|
end
|
177
166
|
end
|
178
167
|
|
168
|
+
describe "param validations" do
|
169
|
+
{
|
170
|
+
"format" => "png -write bad.png",
|
171
|
+
"frame" => "0] -write bad.png [",
|
172
|
+
}.each do |opt, value|
|
173
|
+
it "validates bad opts like #{opt} = '#{value}'" do
|
174
|
+
expect {
|
175
|
+
processor.call(image, "30x30", opt => value)
|
176
|
+
}.to raise_error(Dragonfly::ParamValidators::InvalidParameter)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
179
180
|
end
|