aspect_ratio 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.md +10 -1
- data/aspect_ratio.gemspec +2 -2
- data/lib/aspect_ratio.rb +9 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c727cc38141fc35419ce9564cf6c70e81e640c6b0eb3223a77d2cc51e4884952
|
4
|
+
data.tar.gz: b370b181355375cd1d05d1e4bc69589dc4276f10a3fac2aa264ff93b1e610620
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b6eb6e35e4fd68d95fd73f1dc90e85fcbb0ceaf04f55c037d4677167cab45204ea9eb9d3186498a38c31b02410b616061dc7f4c731fceb564f73851a583ee22
|
7
|
+
data.tar.gz: 71fae0df1912c665fd014db3089412042e77641889fd6b76be68505b6ffb023fc2a7c14095967295622676ef8d349c69590f00541cb994af93497947096502d6
|
data/README.md
CHANGED
@@ -69,7 +69,7 @@ AspectRatio.crop(2048, 768, '4:3');
|
|
69
69
|
|
70
70
|

|
71
71
|
|
72
|
-
### resize(**integer** `x`, **integer** `y`, **integer** `maxX`, **integer** `maxY`)
|
72
|
+
### resize(**integer** `x`, **integer** `y`, **integer** `maxX`, **integer** `maxY`, **boolean** `enlarge`)
|
73
73
|
|
74
74
|
Get resized height and width of an image while perserving the aspect ratio of
|
75
75
|
the image.
|
@@ -78,6 +78,7 @@ the image.
|
|
78
78
|
* **integer** `y` - original image height
|
79
79
|
* **integer** `maxX` - max image width
|
80
80
|
* **integer** `maxY` - max image height
|
81
|
+
* **boolean** `enlarge` - enlarge when original is smaller than the max - default true
|
81
82
|
|
82
83
|
### Return
|
83
84
|
|
@@ -86,4 +87,12 @@ Returns an `Array` of the resized `x` and `y` values:
|
|
86
87
|
* **integer** `x` - resized image width
|
87
88
|
* **integer** `y` - resized image height
|
88
89
|
|
90
|
+
#### Example
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
require 'aspect_ratio'
|
94
|
+
AspectRatio.resize(2048, 768, 640, 640);
|
95
|
+
// [640, 240]
|
96
|
+
```
|
97
|
+
|
89
98
|
## [MIT License](./LICENSE)
|
data/aspect_ratio.gemspec
CHANGED
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = 'aspect_ratio'
|
6
|
-
s.version = '1.0.
|
6
|
+
s.version = '1.0.2'
|
7
7
|
s.date = '2016-04-26'
|
8
8
|
s.summary = 'Image aspect ratio calculation utility'
|
9
9
|
s.description = 'Image aspect ratio calculation utility'
|
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.license = 'MIT'
|
15
15
|
|
16
16
|
s.require_paths = ['lib']
|
17
|
-
s.required_ruby_version = '>= 2.
|
17
|
+
s.required_ruby_version = '>= 2.2.0'
|
18
18
|
s.test_files = s.files.grep(%r{^(test)/})
|
19
19
|
|
20
20
|
s.add_development_dependency 'minitest', '~> 5'
|
data/lib/aspect_ratio.rb
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
require 'bigdecimal'
|
2
2
|
|
3
3
|
module AspectRatio
|
4
|
-
def self.resize(x, y, x_max = nil, y_max = nil)
|
4
|
+
def self.resize(x, y, x_max = nil, y_max = nil, enlarge = true)
|
5
5
|
x = BigDecimal(x)
|
6
6
|
y = BigDecimal(y)
|
7
|
+
x_max = BigDecimal(x_max) if x_max
|
8
|
+
y_max = BigDecimal(y_max) if y_max
|
7
9
|
|
8
10
|
if x_max && y_max
|
11
|
+
return [x.to_i, y.to_i] if !enlarge && x <= x_max && y <= y_max
|
12
|
+
|
9
13
|
# Maximum values of height and width given, aspect ratio preserved.
|
10
14
|
if y > x
|
11
15
|
return [(y_max * x / y).round, y_max]
|
@@ -13,9 +17,13 @@ module AspectRatio
|
|
13
17
|
return [x_max, (x_max * y / x).round]
|
14
18
|
end
|
15
19
|
elsif x_max
|
20
|
+
return [x.to_i, y.to_i] if !enlarge && x <= x_max
|
21
|
+
|
16
22
|
# Width given, height automagically selected to preserve aspect ratio.
|
17
23
|
return [x_max, (x_max * y / x).round]
|
18
24
|
else
|
25
|
+
return [x.to_i, y.to_i] if !enlarge && y <= y_max
|
26
|
+
|
19
27
|
# Height given, width automagically selected to preserve aspect ratio.
|
20
28
|
return [(y_max * x / y).round, y_max]
|
21
29
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aspect_ratio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Trung Lê
|
@@ -46,7 +46,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
46
46
|
requirements:
|
47
47
|
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: 2.
|
49
|
+
version: 2.2.0
|
50
50
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
@@ -54,9 +54,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
54
|
version: '0'
|
55
55
|
requirements: []
|
56
56
|
rubyforge_project:
|
57
|
-
rubygems_version: 2.
|
57
|
+
rubygems_version: 2.7.3
|
58
58
|
signing_key:
|
59
59
|
specification_version: 4
|
60
60
|
summary: Image aspect ratio calculation utility
|
61
61
|
test_files: []
|
62
|
-
has_rdoc:
|