aspect_ratio 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 92580f1d81376b42721c85af7cb5f88ac1ed28e0
4
- data.tar.gz: b14cd9736dfaee1969f9f4478d25f8b5632eabc1
2
+ SHA256:
3
+ metadata.gz: c727cc38141fc35419ce9564cf6c70e81e640c6b0eb3223a77d2cc51e4884952
4
+ data.tar.gz: b370b181355375cd1d05d1e4bc69589dc4276f10a3fac2aa264ff93b1e610620
5
5
  SHA512:
6
- metadata.gz: ce8b64073cd488983082c44078ed0e19944ff55b676a01ed637a0c3c4465529e2538d695a1727a1634d763a04e3de4b0ce5edc3c4c309c0fd04b69abde325bd9
7
- data.tar.gz: 62c7a9aeaa88754d42e65045b8187c20fc1d5a661abf8b079244a8b5cdb310e399aea98170c0ca61c5188529ec70bee74d4f8e6e27bce7a5809cf8be53d7b227
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
  ![Crop with fixed ratio](./aspect.png)
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.1'
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.1.0'
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.1
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.1.0
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.4.5.1
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: