scene7-wrapper 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/scene7/crop.rb +7 -6
- data/scene7-wrapper.gemspec +1 -1
- data/spec/scene7/crop_spec.rb +2 -6
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.4
|
data/lib/scene7/crop.rb
CHANGED
@@ -3,17 +3,18 @@ require 'active_support/core_ext'
|
|
3
3
|
module Scene7
|
4
4
|
module Crop
|
5
5
|
def self.convert_from_scale_first_and_format(params, additional_params = {})
|
6
|
-
format_url_params convert_params_from_scale_first(params, additional_params
|
6
|
+
format_url_params convert_params_from_scale_first(params), additional_params
|
7
7
|
end
|
8
8
|
|
9
|
-
def self.format_url_params(params)
|
9
|
+
def self.format_url_params(params, additional_params = {})
|
10
10
|
require 'cgi' unless defined?(CGI) && defined?(CGI::escape)
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
query = "scl=#{params.delete(:scale_factor)}&crop=#{params.delete(:x).round},#{params.delete(:y).round},#{params.delete(:width).round},#{params.delete(:height).round}&qlt=#{params.delete(:quality)}"
|
13
|
+
query << "&" + additional_params.map {|k, v| "#{k}=#{CGI.escape(v.to_s)}" }.join('&') if additional_params.length > 0
|
14
|
+
query
|
14
15
|
end
|
15
16
|
|
16
|
-
def self.convert_params_from_scale_first(orig_params
|
17
|
+
def self.convert_params_from_scale_first(orig_params)
|
17
18
|
{}.tap do |params|
|
18
19
|
scale_factor = orig_params[:scale_factor].to_f
|
19
20
|
params[:scale_factor] = 1.0 / scale_factor
|
@@ -22,7 +23,7 @@ module Scene7
|
|
22
23
|
params[:x] = (orig_params[:x].to_f / scale_factor).round
|
23
24
|
params[:y] = (orig_params[:y].to_f / scale_factor).round
|
24
25
|
params[:quality] = orig_params[:quality] || 95
|
25
|
-
end
|
26
|
+
end
|
26
27
|
end
|
27
28
|
end
|
28
29
|
end
|
data/scene7-wrapper.gemspec
CHANGED
data/spec/scene7/crop_spec.rb
CHANGED
@@ -57,8 +57,9 @@ describe Scene7::Crop do
|
|
57
57
|
} }
|
58
58
|
|
59
59
|
it "converts, then formats" do
|
60
|
-
subject.convert_from_scale_first_and_format(params).should == "scl=0.5&crop=50,125,225,150&qlt=70"
|
60
|
+
subject.convert_from_scale_first_and_format(params, :extra => true).should == "scl=0.5&crop=50,125,225,150&qlt=70&extra=true"
|
61
61
|
end
|
62
|
+
|
62
63
|
end
|
63
64
|
end
|
64
65
|
|
@@ -87,11 +88,6 @@ describe Scene7::Crop do
|
|
87
88
|
it "converts the top coordinate from the scale-first style" do
|
88
89
|
@result[:y].should == 125
|
89
90
|
end
|
90
|
-
|
91
|
-
it "accepts additional params" do
|
92
|
-
@result = subject.convert_params_from_scale_first(params, {:extra => true})
|
93
|
-
@result[:extra].should == true
|
94
|
-
end
|
95
91
|
end
|
96
92
|
end
|
97
93
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scene7-wrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 4
|
10
|
+
version: 0.3.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Brian Rose
|