imgry 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/imgry/geometry.rb +10 -3
- data/lib/imgry/version.rb +1 -1
- data/spec/imgry/geometry_spec.rb +32 -0
- metadata +4 -3
data/lib/imgry/geometry.rb
CHANGED
@@ -10,10 +10,15 @@ module Imgry
|
|
10
10
|
ask_height ||= 0
|
11
11
|
aspect_ratio = orig_width.to_f / orig_height.to_f
|
12
12
|
|
13
|
-
scale = Proc.new do
|
14
|
-
|
13
|
+
scale = Proc.new do |ask_is_maximum = true|
|
14
|
+
ask_aspect_ratio = ask_width.to_f / ask_height.to_f
|
15
|
+
# Fill requested height if result should cover narrower aspect or should be contained within wider aspect
|
16
|
+
fill_height = (ask_is_maximum && ask_aspect_ratio > aspect_ratio) || (!ask_is_maximum && ask_aspect_ratio < aspect_ratio)
|
17
|
+
if ask_width == 0 || (ask_height != 0 && fill_height)
|
18
|
+
# Fill height, calculate width
|
15
19
|
new_width, new_height = scale_by_height(ask_height, aspect_ratio)
|
16
20
|
else
|
21
|
+
# Fill width, calculate height
|
17
22
|
new_width, new_height = scale_by_width(ask_width, aspect_ratio)
|
18
23
|
end
|
19
24
|
end
|
@@ -21,6 +26,8 @@ module Imgry
|
|
21
26
|
case op
|
22
27
|
when '!'
|
23
28
|
new_width, new_height = ask_width.to_i, ask_height.to_i
|
29
|
+
when '^'
|
30
|
+
scale.call(false)
|
24
31
|
when '>'
|
25
32
|
scale.call if orig_width > ask_width || orig_height > ask_height
|
26
33
|
when '<'
|
@@ -60,6 +67,6 @@ module Imgry
|
|
60
67
|
end
|
61
68
|
[width, height, x, y, flag]
|
62
69
|
end
|
63
|
-
|
70
|
+
|
64
71
|
end
|
65
72
|
end
|
data/lib/imgry/version.rb
CHANGED
data/spec/imgry/geometry_spec.rb
CHANGED
@@ -17,6 +17,22 @@ describe Imgry::Geometry do
|
|
17
17
|
size.should == [400, 300]
|
18
18
|
end
|
19
19
|
|
20
|
+
it 'fits given maximum dimensions with aspect ratio maintained when image aspect > 1' do
|
21
|
+
size = Imgry::Geometry.scale(1024, 768, "300x600")
|
22
|
+
size.should == [300, 225]
|
23
|
+
|
24
|
+
size = Imgry::Geometry.scale(1024, 768, "600x300")
|
25
|
+
size.should == [400, 300]
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'fits given maximum dimensions with aspect ratio maintained when image aspect < 1' do
|
29
|
+
size = Imgry::Geometry.scale(768, 1024, "300x600")
|
30
|
+
size.should == [300, 400]
|
31
|
+
|
32
|
+
size = Imgry::Geometry.scale(768, 1024, "600x300")
|
33
|
+
size.should == [225, 300]
|
34
|
+
end
|
35
|
+
|
20
36
|
it 'shrinks to a size when dimensions are larger then corresponding width/height' do
|
21
37
|
size = Imgry::Geometry.scale(1024, 768, "600x600>")
|
22
38
|
size.should == [600, 450]
|
@@ -30,6 +46,22 @@ describe Imgry::Geometry do
|
|
30
46
|
size.should == [1024, 768]
|
31
47
|
|
32
48
|
size = Imgry::Geometry.scale(300, 400, "600x600<")
|
49
|
+
size.should == [450, 600]
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'covers minimum specified dimensions with aspect ratio maintained when image aspect > 1' do
|
53
|
+
size = Imgry::Geometry.scale(1024, 768, "100x600^")
|
54
|
+
size.should == [800, 600]
|
55
|
+
|
56
|
+
size = Imgry::Geometry.scale(1024, 768, "600x100^")
|
57
|
+
size.should == [600, 450]
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'covers minimum specified dimensions with aspect ratio maintained when image aspect < 1' do
|
61
|
+
size = Imgry::Geometry.scale(768, 1024, "100x600^")
|
62
|
+
size.should == [450, 600]
|
63
|
+
|
64
|
+
size = Imgry::Geometry.scale(768, 1024, "600x100^")
|
33
65
|
size.should == [600, 800]
|
34
66
|
end
|
35
67
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imgry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-02-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
79
|
version: 1.3.6
|
80
80
|
requirements: []
|
81
81
|
rubyforge_project:
|
82
|
-
rubygems_version: 1.8.
|
82
|
+
rubygems_version: 1.8.25
|
83
83
|
signing_key:
|
84
84
|
specification_version: 3
|
85
85
|
summary: Fast image resizing/cropping designed for JRuby with MRI support
|
@@ -99,3 +99,4 @@ test_files:
|
|
99
99
|
- spec/support/mexico-cmyk.jpg
|
100
100
|
- spec/support/transparent_background.png
|
101
101
|
- spec/support/transparent_background_saved.png
|
102
|
+
has_rdoc:
|