g1nn13-image_science 1.2.6 → 1.2.7

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.
@@ -1,3 +1,8 @@
1
+ === 1.2.7 / 2010-05-26
2
+
3
+ * removed redundant method cropped_to_fit
4
+ * added image files for tests
5
+
1
6
  === 1.2.6 / 2010-05-26
2
7
 
3
8
  * Now based on ImageScience 1.2.1
@@ -5,5 +5,10 @@ Rakefile
5
5
  bench.rb
6
6
  bin/image_science_thumb
7
7
  lib/image_science.rb
8
+ test/bearry.png
9
+ test/biggie.png
10
+ test/godzilla.png
11
+ test/landscape.png
8
12
  test/pix.png
13
+ test/portrait.png
9
14
  test/test_image_science.rb
@@ -13,7 +13,7 @@ require 'inline'
13
13
  # Based on ImageScience 1.2.1
14
14
 
15
15
  class ImageScience
16
- VERSION = '1.2.6'
16
+ VERSION = '1.2.7'
17
17
 
18
18
  ##
19
19
  # The top-level image loader opens +path+ and then yields the image.
@@ -57,79 +57,6 @@ class ImageScience
57
57
  def buffer(extension) # :yields: image
58
58
  end
59
59
 
60
-
61
- ##
62
- # Resizes an image to the specified size without stretching or
63
- # compressing the original. If the aspect ratio of the new height/width
64
- # does not match the aspect ratio of the original (as when converting
65
- # portrait to landscape or landscape to portrait), the resulting
66
- # image will be cropped. Cropping preserves the center of the image,
67
- # with content trimmed evenly from the top and bottom and/or left and
68
- # right edges of the image. This can cause some less than ideal
69
- # conversions. For example, converting a portrait to a landscape can
70
- # result in the portrait's head being cut off.
71
-
72
- def resize_with_crop(width, height, &block)
73
-
74
- # ---------------------------------------------------------------
75
- # We want to adjust both height and width by the same ratio,
76
- # so the image is not stretched. Adjust everything by the
77
- # larger ratio, so that portrait to landscape and landscape
78
- # to portrait transformations come out right.
79
- # ---------------------------------------------------------------
80
- src2target_height_ratio = height.to_f / self.height
81
- src2target_width_ratio = width.to_f / self.width
82
- height_ratio_is_larger = src2target_height_ratio > src2target_width_ratio
83
- if height_ratio_is_larger
84
- target_height = (self.height * src2target_height_ratio).round
85
- target_width = (self.width * src2target_height_ratio).round
86
- else
87
- target_height = (self.height * src2target_width_ratio).round
88
- target_width = (self.width * src2target_width_ratio).round
89
- end
90
-
91
- # ---------------------------------------------------------------
92
- # Create a version of this image whose longest
93
- # side is equal to max_dimension. We'll add two
94
- # to this value, since floating point arithmetic
95
- # often produces values 1-2 pixels short of what we want.
96
- # ---------------------------------------------------------------
97
- max_dimension = (target_height > target_width ?
98
- target_height : target_width)
99
-
100
- self.thumbnail(max_dimension + 2) do |img1|
101
- top, left = 0, 0
102
- top = (img1.height - height) / 2 unless img1.height < height
103
- left = (img1.width - width) / 2 unless img1.width < width
104
- right = width + left
105
- bottom = height + top
106
-
107
- # ---------------------------------------------------------------
108
- # Crop the resized image evenly at top/bottom, left/right,
109
- # so that we preserve the center.
110
- # ---------------------------------------------------------------
111
- result = img1.with_crop(left, top, right, bottom) do |img2|
112
- if block_given?
113
- yield img2
114
- else
115
- return img2
116
- end
117
- end
118
-
119
- if result.nil?
120
- message = "Crop/resize failed... is some dimension is out of bounds?"
121
- message += "Original Height = #{self.height}, Width = #{self.width}"
122
- message += "Target Height = #{height}, Width = #{width}"
123
- message += "Actual Height = #{self.height}, Width = #{self.width}"
124
- message += "Left=#{left}, Top=#{top}, Right=#{right}, Bottom=#{bottom}"
125
- raise message
126
- end
127
-
128
-
129
- end
130
- end
131
-
132
-
133
60
  ##
134
61
  # Resizes the image to +width+ and +height+ using a cubic-bspline
135
62
  # filter and yields the new image.
@@ -197,20 +124,71 @@ class ImageScience
197
124
  end
198
125
 
199
126
  ##
200
- # Creates a square thumbnail of the image cropping the longest edge
201
- # to match the shortest edge, resizes to +size+, and yields the new
202
- # image.
127
+ # Resizes an image to the specified size without stretching or
128
+ # compressing the original. If the aspect ratio of the new height/width
129
+ # does not match the aspect ratio of the original (as when converting
130
+ # portrait to landscape or landscape to portrait), the resulting
131
+ # image will be cropped. Cropping preserves the center of the image,
132
+ # with content trimmed evenly from the top and bottom and/or left and
133
+ # right edges of the image. This can cause some less than ideal
134
+ # conversions. For example, converting a portrait to a landscape can
135
+ # result in the portrait's head being cut off.
203
136
 
204
- def cropped_to_fit(width, height) # :yields: image
205
- w, h = width, height
206
- l, t, r, b, half = 0, 0, w, h, (w - h).abs / 2
137
+ def resize_with_crop(width, height, &block)
207
138
 
208
- l, r = half, half + h if w > h
209
- t, b = half, half + w if h > w
139
+ # ---------------------------------------------------------------
140
+ # We want to adjust both height and width by the same ratio,
141
+ # so the image is not stretched. Adjust everything by the
142
+ # larger ratio, so that portrait to landscape and landscape
143
+ # to portrait transformations come out right.
144
+ # ---------------------------------------------------------------
145
+ src2target_height_ratio = height.to_f / self.height
146
+ src2target_width_ratio = width.to_f / self.width
147
+ height_ratio_is_larger = src2target_height_ratio > src2target_width_ratio
148
+
149
+ if height_ratio_is_larger
150
+ target_height = (self.height * src2target_height_ratio).round
151
+ target_width = (self.width * src2target_height_ratio).round
152
+ else
153
+ target_height = (self.height * src2target_width_ratio).round
154
+ target_width = (self.width * src2target_width_ratio).round
155
+ end
210
156
 
211
- with_crop(l, t, r, b) do |img|
212
- img.thumbnail(size) do |thumb|
213
- yield thumb
157
+ # ---------------------------------------------------------------
158
+ # Create a version of this image whose longest
159
+ # side is equal to max_dimension. We'll add two
160
+ # to this value, since floating point arithmetic
161
+ # often produces values 1-2 pixels short of what we want.
162
+ # ---------------------------------------------------------------
163
+ max_dimension = (target_height > target_width ?
164
+ target_height : target_width)
165
+
166
+ self.thumbnail(max_dimension + 2) do |img1|
167
+ top, left = 0, 0
168
+ top = (img1.height - height) / 2 unless img1.height < height
169
+ left = (img1.width - width) / 2 unless img1.width < width
170
+ right = width + left
171
+ bottom = height + top
172
+
173
+ # ---------------------------------------------------------------
174
+ # Crop the resized image evenly at top/bottom, left/right,
175
+ # so that we preserve the center.
176
+ # ---------------------------------------------------------------
177
+ result = img1.with_crop(left, top, right, bottom) do |img2|
178
+ if block_given?
179
+ yield img2
180
+ else
181
+ return img2
182
+ end
183
+ end
184
+
185
+ if result.nil?
186
+ message = "Crop/resize failed... is some dimension is out of bounds?"
187
+ message += "Original Height = #{self.height}, Width = #{self.width}"
188
+ message += "Target Height = #{height}, Width = #{width}"
189
+ message += "Actual Height = #{self.height}, Width = #{self.width}"
190
+ message += "Left=#{left}, Top=#{top}, Right=#{right}, Bottom=#{bottom}"
191
+ raise message
214
192
  end
215
193
  end
216
194
  end
Binary file
Binary file
Binary file
Binary file
Binary file
metadata CHANGED
@@ -1,141 +1,87 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: g1nn13-image_science
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 1
7
- - 2
8
- - 6
9
- version: 1.2.6
4
+ version: 1.2.7
10
5
  platform: ruby
11
6
  authors:
12
7
  - jim nist
13
8
  autorequire:
14
9
  bindir: bin
15
- cert_chain:
16
- - |
17
- -----BEGIN CERTIFICATE-----
18
- MIIDNjCCAh6gAwIBAgIBADANBgkqhkiG9w0BAQUFADBBMQwwCgYDVQQDDANqaW0x
19
- HDAaBgoJkiaJk/IsZAEZFgxob3RlbGljb3B0ZXIxEzARBgoJkiaJk/IsZAEZFgNj
20
- b20wHhcNMTAwNTI2MTYwNTM5WhcNMTEwNTI2MTYwNTM5WjBBMQwwCgYDVQQDDANq
21
- aW0xHDAaBgoJkiaJk/IsZAEZFgxob3RlbGljb3B0ZXIxEzARBgoJkiaJk/IsZAEZ
22
- FgNjb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCzbudw4TyxDTEj
23
- /UMsEt2LFWmDiEKmyKHnHiPdjINn/wY8yYw1oujRj2c2iXlaon68u8G+1qacfyd0
24
- gpHPFQfqBFKLDtPgPffzAkY8fvW4MgjRYFcymdpiVGpHCoTgvhO9Efsrd/d8Ja4n
25
- oeEPNHdXr/bHwLhgIAup6JYQAZSL1DY77co3rbvY1xqovbc6tg/M7cbXPp1lmONS
26
- XwIHPWjsl3mL1IWEQPt2dmPy6ZLYliKowdGlDUblupXuVlO9cS67yf3MlJp874mY
27
- yH1qAwSK/Toe2L39TTi/Hyx6HMFECTmkLUT/4X2z6zWUlK0e5Hr8ViBCzh2BTOyO
28
- jojoYo7tAgMBAAGjOTA3MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQW
29
- BBQ1LMdE7DCtf+7x6tJAqGRMKMtVXDANBgkqhkiG9w0BAQUFAAOCAQEAIu7ygDoV
30
- g5wdi3wWR//1yK86vQe36luyolo3GL+Z0FmIIA+tdAPZtMAlnFasOSfLVDdkxb3O
31
- J2MLyH5KHY5asc27J+Y/zUofGWj5JgQZIg+gAGcDuq94kr4NXgFTL4khE3zhI4uH
32
- 65+zkHrnetmZPilpTbFjzvM1SfuzrU9t+ugEu7R1vmAQdhdcgSwXr0MYPy5oZWgQ
33
- eayeSBRjd6tzceXRmaZYWDH2wra509l63UgJw6dsNgWzQH1XQ1XzqJXX/J8FRgDI
34
- n3ugwImcS/YB+ZQ3TQ3uKX8E5Ikos7YH0Pc/WRQnMzcjBmNtx7GsV9MC9Qx/i+YC
35
- UHHftgnvI+YPGw==
36
- -----END CERTIFICATE-----
10
+ cert_chain: []
37
11
 
38
12
  date: 2010-05-26 00:00:00 -04:00
39
13
  default_executable:
40
14
  dependencies:
41
15
  - !ruby/object:Gem::Dependency
42
16
  name: hoe
43
- prerelease: false
44
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
45
20
  requirements:
46
21
  - - ">="
47
22
  - !ruby/object:Gem::Version
48
- segments:
49
- - 2
50
- - 5
51
- - 0
52
23
  version: 2.5.0
53
- type: :runtime
54
- version_requirements: *id001
24
+ version:
55
25
  - !ruby/object:Gem::Dependency
56
26
  name: gemcutter
57
- prerelease: false
58
- requirement: &id002 !ruby/object:Gem::Requirement
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
59
30
  requirements:
60
31
  - - ">="
61
32
  - !ruby/object:Gem::Version
62
- segments:
63
- - 0
64
- - 3
65
- - 0
66
33
  version: 0.3.0
67
- type: :runtime
68
- version_requirements: *id002
34
+ version:
69
35
  - !ruby/object:Gem::Dependency
70
36
  name: hoe-doofus
71
- prerelease: false
72
- requirement: &id003 !ruby/object:Gem::Requirement
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
73
40
  requirements:
74
41
  - - ">="
75
42
  - !ruby/object:Gem::Version
76
- segments:
77
- - 1
78
- - 0
79
- - 0
80
43
  version: 1.0.0
81
- type: :development
82
- version_requirements: *id003
44
+ version:
83
45
  - !ruby/object:Gem::Dependency
84
46
  name: hoe-git
85
- prerelease: false
86
- requirement: &id004 !ruby/object:Gem::Requirement
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
87
50
  requirements:
88
51
  - - ">="
89
52
  - !ruby/object:Gem::Version
90
- segments:
91
- - 1
92
- - 3
93
- - 0
94
53
  version: 1.3.0
95
- type: :development
96
- version_requirements: *id004
54
+ version:
97
55
  - !ruby/object:Gem::Dependency
98
56
  name: hoe-telicopter
99
- prerelease: false
100
- requirement: &id005 !ruby/object:Gem::Requirement
57
+ type: :development
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Requirement
101
60
  requirements:
102
61
  - - ">="
103
62
  - !ruby/object:Gem::Version
104
- segments:
105
- - 1
106
- - 0
107
- - 0
108
63
  version: 1.0.0
109
- type: :development
110
- version_requirements: *id005
64
+ version:
111
65
  - !ruby/object:Gem::Dependency
112
66
  name: minitest
113
- prerelease: false
114
- requirement: &id006 !ruby/object:Gem::Requirement
67
+ type: :development
68
+ version_requirement:
69
+ version_requirements: !ruby/object:Gem::Requirement
115
70
  requirements:
116
71
  - - ">="
117
72
  - !ruby/object:Gem::Version
118
- segments:
119
- - 1
120
- - 5
121
- - 0
122
73
  version: 1.5.0
123
- type: :development
124
- version_requirements: *id006
74
+ version:
125
75
  - !ruby/object:Gem::Dependency
126
76
  name: hoe
127
- prerelease: false
128
- requirement: &id007 !ruby/object:Gem::Requirement
77
+ type: :development
78
+ version_requirement:
79
+ version_requirements: !ruby/object:Gem::Requirement
129
80
  requirements:
130
81
  - - ">="
131
82
  - !ruby/object:Gem::Version
132
- segments:
133
- - 2
134
- - 6
135
- - 0
136
83
  version: 2.6.0
137
- type: :development
138
- version_requirements: *id007
84
+ version:
139
85
  description: |-
140
86
  g1nn13 fork changes:
141
87
 
@@ -171,7 +117,12 @@ files:
171
117
  - bench.rb
172
118
  - bin/image_science_thumb
173
119
  - lib/image_science.rb
120
+ - test/bearry.png
121
+ - test/biggie.png
122
+ - test/godzilla.png
123
+ - test/landscape.png
174
124
  - test/pix.png
125
+ - test/portrait.png
175
126
  - test/test_image_science.rb
176
127
  has_rdoc: true
177
128
  homepage: http://github.com/g1nn13/image_science
@@ -187,20 +138,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
187
138
  requirements:
188
139
  - - ">="
189
140
  - !ruby/object:Gem::Version
190
- segments:
191
- - 0
192
141
  version: "0"
142
+ version:
193
143
  required_rubygems_version: !ruby/object:Gem::Requirement
194
144
  requirements:
195
145
  - - ">="
196
146
  - !ruby/object:Gem::Version
197
- segments:
198
- - 0
199
147
  version: "0"
148
+ version:
200
149
  requirements: []
201
150
 
202
151
  rubyforge_project: g1nn13-image_science
203
- rubygems_version: 1.3.6
152
+ rubygems_version: 1.3.5
204
153
  signing_key:
205
154
  specification_version: 3
206
155
  summary: "g1nn13 fork changes: * added buffer() method to get image buffer for writing (to Amazon S3) * added fit_within() method to resize an image to fit within a specified height and width without changing the image's aspect ratio * added resize_with_crop() to resize and crop images where the target aspect ratio differs from the original aspect ratio"
data.tar.gz.sig DELETED
Binary file
metadata.gz.sig DELETED
@@ -1,5 +0,0 @@
1
- Pl\3N��>KA���C��y{�[ZT��}��ͻC�ه?��M��ƅs�#�):��
2
- C����B�du�9��
3
- xܩ�DH�@e��P8���X��e<mm��-�m��N�b��4�Î`b�]����
4
- �WZ�rO�.!�~2nB
5
- �!;w(t}�e�0Fh#[��t�͎7(�ő�?�*!�ӛ^�Q��j��s���Q��8�O���; �+gg��v��%�u �t}����Ǧ]�� E�ʞ]�&����_