imageproxy 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.4.0
data/imageproxy.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "imageproxy"
8
- s.version = "0.3.0"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Erik Hanson"]
@@ -11,7 +11,8 @@ module Imageproxy
11
11
  def curl(url, options={})
12
12
  user_agent = options[:user_agent] || "imageproxy"
13
13
  timeout = options[:timeout] ? "-m #{options[:timeout]} " : ""
14
- %|curl #{timeout}-L -s -A "#{user_agent}" "#{url}"|
14
+ output = options[:output]
15
+ %|curl #{timeout}-L -s -A "#{user_agent}" #{output ? "-o #{output} ": ""}"#{url}"|
15
16
  end
16
17
 
17
18
  def to_path(obj)
@@ -6,16 +6,26 @@ module Imageproxy
6
6
 
7
7
  def initialize(options)
8
8
  @options = options
9
- if (!(options.resize || options.thumbnail || options.rotate || options.flip || options.format || options.quality))
9
+ if (!(options.resize || options.thumbnail || options.rotate || options.flip || options.format ||
10
+ options.quality || options.overlay))
10
11
  raise "Missing action or illegal parameter value"
11
12
  end
12
13
  end
13
14
 
14
15
  def execute(user_agent=nil, timeout=nil)
15
- execute_command %'#{curl options.source, :user_agent => user_agent, :timeout => timeout} | convert - #{convert_options} #{new_format}#{file.path}'
16
- file
16
+ if options.overlay
17
+ @overlay_file ||= Tempfile.new("imageproxy").tap(&:close)
18
+ execute_command(curl options.overlay, :user_agent => user_agent, :timeout => timeout, :output => @overlay_file.path)
19
+ execute_command curl(options.source, :user_agent => user_agent, :timeout => timeout) +
20
+ "| composite #{@overlay_file.path} - - | convert - #{convert_options} #{new_format}#{file.path}"
21
+ file
22
+ else
23
+ execute_command %'#{curl options.source, :user_agent => user_agent, :timeout => timeout} | convert - #{convert_options} #{new_format}#{file.path}'
24
+ file
25
+ end
17
26
  end
18
27
 
28
+
19
29
  def convert_options
20
30
  convert_options = []
21
31
  convert_options << "-resize #{resize_thumbnail_options(options.resize)}" if options.resize
@@ -15,6 +15,7 @@ module Imageproxy
15
15
  @hash["source"] = @hash.delete("src") if @hash.has_key?("src")
16
16
 
17
17
  unescape_source
18
+ unescape_overlay
18
19
  unescape_signature
19
20
  check_parameters
20
21
  end
@@ -48,6 +49,10 @@ module Imageproxy
48
49
  @hash['source'] &&= CGI.unescape(CGI.unescape(@hash['source']))
49
50
  end
50
51
 
52
+ def unescape_overlay
53
+ @hash['overlay'] &&= CGI.unescape(CGI.unescape(@hash['overlay']))
54
+ end
55
+
51
56
  def unescape_signature
52
57
  @hash['signature'] &&= URI.unescape(@hash['signature'])
53
58
  end
@@ -19,6 +19,9 @@ module Imageproxy
19
19
  raw_source = "http://eahanson.s3.amazonaws.com/imageproxy/sample.png"
20
20
  source = CGI.escape(URI.escape(URI.escape(raw_source)))
21
21
 
22
+ raw_overlay = "http://www.imagemagick.org/image/smile.gif"
23
+ overlay = CGI.escape(URI.escape(URI.escape(raw_overlay)))
24
+
22
25
  html += <<-HTML
23
26
  <h3>Original Image</h3>
24
27
  <a href="#{raw_source}">#{raw_source}</a>
@@ -41,7 +44,10 @@ module Imageproxy
41
44
  ["Rotating to a non-90-degree increment", "/convert?rotate=120&source=#{source}"],
42
45
  ["Rotating to a non-90-degree increment with a background color", "/convert?rotate=120&background=%23ff00ff&source=#{source}"],
43
46
 
44
- ["Combo", "/convert?resize=100x100&shape=cut&rotate=45&background=%23ff00ff&source=#{source}"]
47
+ ["Combo", "/convert?resize=100x100&shape=cut&rotate=45&background=%23ff00ff&source=#{source}"],
48
+
49
+ ["Compositing", "/convert?source=#{source}&overlay=#{overlay}"],
50
+ ["Composite and then do something else", "/convert?source=#{source}&overlay=#{overlay}&rotate=50"]
45
51
  ]
46
52
 
47
53
  examples.each do |example|
data/spec/convert_spec.rb CHANGED
@@ -148,4 +148,24 @@ describe Imageproxy::Convert do
148
148
  command({:resize => "10x10"}).convert_options.should_not match /interlace/
149
149
  end
150
150
  end
151
+
152
+ context "when compositing" do
153
+ before do
154
+ @command = command("overlay" => "http%3A%2F%2Fexample.com%2Fframe.jpg")
155
+ @command.stub!(:file).and_return(@mock_file)
156
+ @command.stub!(:system)
157
+ end
158
+
159
+ it "should fetch both the overlay and the source, and call the composite command to composit the overlay on top of the source" do
160
+ @command.should_receive(:execute_command).with(%r|curl -L -s -A "imageproxy" -o [^ ]+ "http://example.com/frame.jpg"|)
161
+ @command.should_receive(:execute_command).with(
162
+ %r{curl -L -s -A "imageproxy" "http://example.com/dog.jpg" | composite [^ ]+ - - | convert - png:/mock/file/path})
163
+ @command.execute
164
+ end
165
+
166
+ it "should return the output file" do
167
+ @command.stub!(:execute_command)
168
+ @command.execute.should == @mock_file
169
+ end
170
+ end
151
171
  end
data/spec/options_spec.rb CHANGED
@@ -32,6 +32,23 @@ describe Imageproxy::Options do
32
32
  end
33
33
  end
34
34
 
35
+ context "overlay" do
36
+ context "when double-escaped" do
37
+ subject { Imageproxy::Options.new "/convert/overlay/http%253A%252F%252Fexample.com%252Fframe.jpg", {} }
38
+ it("should unescape") { subject.overlay.should == "http://example.com/frame.jpg" }
39
+ end
40
+
41
+ context "when escaped" do
42
+ subject { Imageproxy::Options.new "/convert/overlay/http%3A%2F%2Fexample.com%2Fframe.jpg", {} }
43
+ it("should unescape") { subject.overlay.should == "http://example.com/frame.jpg" }
44
+ end
45
+
46
+ context "when not escaped" do
47
+ subject { Imageproxy::Options.new "/convert/overlay/foo", {} }
48
+ it("should not unescape") { subject.overlay.should == "foo" }
49
+ end
50
+ end
51
+
35
52
  context "signature" do
36
53
  context "when escaped with + signs" do
37
54
  subject { Imageproxy::Options.new "/process/source/foo/signature/foo+bar", {} }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imageproxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-05-16 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
16
- requirement: &31896780 !ruby/object:Gem::Requirement
16
+ requirement: &18224420 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *31896780
24
+ version_requirements: *18224420
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &31896260 !ruby/object:Gem::Requirement
27
+ requirement: &18223400 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *31896260
35
+ version_requirements: *18223400
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: mime-types
38
- requirement: &31895740 !ruby/object:Gem::Requirement
38
+ requirement: &18222140 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *31895740
46
+ version_requirements: *18222140
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: heroku
49
- requirement: &31895220 !ruby/object:Gem::Requirement
49
+ requirement: &18220740 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *31895220
57
+ version_requirements: *18220740
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: shotgun
60
- requirement: &31894620 !ruby/object:Gem::Requirement
60
+ requirement: &18219680 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *31894620
68
+ version_requirements: *18219680
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
- requirement: &31894020 !ruby/object:Gem::Requirement
71
+ requirement: &18218480 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *31894020
79
+ version_requirements: *18218480
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rack-test
82
- requirement: &31893420 !ruby/object:Gem::Requirement
82
+ requirement: &18214760 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *31893420
90
+ version_requirements: *18214760
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: awesome_print
93
- requirement: &31892720 !ruby/object:Gem::Requirement
93
+ requirement: &18213580 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *31892720
101
+ version_requirements: *18213580
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: jeweler
104
- requirement: &31892240 !ruby/object:Gem::Requirement
104
+ requirement: &18212420 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,7 +109,7 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *31892240
112
+ version_requirements: *18212420
113
113
  description: A image processing proxy server, written in Ruby as a Rack application.
114
114
  Requires ImageMagick.
115
115
  email: erik@eahanson.com
@@ -163,7 +163,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
163
163
  version: '0'
164
164
  segments:
165
165
  - 0
166
- hash: -4468213037548042789
166
+ hash: 2692885004862731431
167
167
  required_rubygems_version: !ruby/object:Gem::Requirement
168
168
  none: false
169
169
  requirements: