g1nn13-image_science 1.2.4 → 1.2.5

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.
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ === 1.2.5 / 2010-01-26
2
+
3
+ * 1 tweak
4
+
5
+ * added some tests
6
+
1
7
  === 1.2.4 / 2010-01-26
2
8
 
3
9
  * 1 minor enhancements, one little mod
data/lib/image_science.rb CHANGED
@@ -11,7 +11,7 @@ require 'inline'
11
11
  # http://seattlerb.rubyforge.org/ImageScience.html
12
12
 
13
13
  class ImageScience
14
- VERSION = '1.2.4'
14
+ VERSION = '1.2.5'
15
15
 
16
16
  ##
17
17
  # The top-level image loader opens +path+ and then yields the image.
@@ -116,6 +116,7 @@ class ImageScience
116
116
  end
117
117
 
118
118
  self.resize(w.to_i, h.to_i) do |image|
119
+ puts image.nil? ? "resize() yielded nil" : "image yielded #{image.width} x #{image.height}"
119
120
  yield image
120
121
  end
121
122
  end
@@ -16,8 +16,13 @@ MiniTest::Unit.autorun
16
16
  class TestImageScience < MiniTest::Unit::TestCase
17
17
  #class TestImageScience < Test::Unit::TestCase
18
18
  def setup
19
- @path = 'test/pix.png'
20
- @tmppath = 'test/pix-tmp.png'
19
+ @pix = 'test/pix.png' # 50 x 50
20
+ @bearry = 'test/bearry.png' # 323 x 24
21
+ @biggie = 'test/biggie.png' # 800 x 600
22
+ @godzilla = 'test/godzilla.png' # 300 x 399
23
+ @landscape = 'test/landscape.png' # 400 x 300
24
+ @portrait = 'test/portrait.png' # 300 x 500
25
+ @tmppath = 'test/tmp.png'
21
26
  @h = @w = 50
22
27
  end
23
28
 
@@ -26,7 +31,7 @@ class TestImageScience < MiniTest::Unit::TestCase
26
31
  end
27
32
 
28
33
  def test_class_with_image
29
- ImageScience.with_image @path do |img|
34
+ ImageScience.with_image @pix do |img|
30
35
  assert_kind_of ImageScience, img
31
36
  assert_equal @h, img.height
32
37
  assert_equal @w, img.width
@@ -44,7 +49,7 @@ class TestImageScience < MiniTest::Unit::TestCase
44
49
 
45
50
  def test_class_with_image_missing
46
51
  assert_raises TypeError do
47
- ImageScience.with_image @path + "nope" do |img|
52
+ ImageScience.with_image @pix + "nope" do |img|
48
53
  flunk
49
54
  end
50
55
  end
@@ -53,17 +58,18 @@ class TestImageScience < MiniTest::Unit::TestCase
53
58
  ##
54
59
  # the assert_raises RuntimeError is not working on our setup don't have time
55
60
  # to investigate right now. TODO: figure out why
61
+
56
62
  def test_class_with_image_missing_with_img_extension
57
63
 
58
64
  # assert_raises RuntimeError do
59
- assert_nil ImageScience.with_image("nope#{@path}") do |img|
65
+ assert_nil ImageScience.with_image("nope#{@pix}") do |img|
60
66
  flunk
61
67
  end
62
68
  # end
63
69
  end
64
70
 
65
71
  def test_class_with_image_from_memory
66
- data = File.new(@path).binmode.read
72
+ data = File.new(@pix).binmode.read
67
73
 
68
74
  ImageScience.with_image_from_memory data do |img|
69
75
  assert_kind_of ImageScience, img
@@ -90,7 +96,7 @@ class TestImageScience < MiniTest::Unit::TestCase
90
96
  end
91
97
 
92
98
  def test_resize
93
- ImageScience.with_image @path do |img|
99
+ ImageScience.with_image @pix do |img|
94
100
  img.resize(25, 25) do |thumb|
95
101
  assert thumb.save(@tmppath)
96
102
  end
@@ -106,7 +112,7 @@ class TestImageScience < MiniTest::Unit::TestCase
106
112
  end
107
113
 
108
114
  def test_buffer_return
109
- ImageScience.with_image @path do |img|
115
+ ImageScience.with_image @pix do |img|
110
116
  img.resize(25, 25) do |thumb|
111
117
  assert thumb.buffer('.jpg')
112
118
  end
@@ -114,7 +120,7 @@ class TestImageScience < MiniTest::Unit::TestCase
114
120
  end
115
121
 
116
122
  def test_buffer_yield
117
- ImageScience.with_image @path do |img|
123
+ ImageScience.with_image @pix do |img|
118
124
  img.resize(25, 25) do |thumb|
119
125
  thumb.buffer('.jpg') do |buffer|
120
126
  assert buffer
@@ -124,7 +130,7 @@ class TestImageScience < MiniTest::Unit::TestCase
124
130
  end
125
131
 
126
132
  def test_resize_floats
127
- ImageScience.with_image @path do |img|
133
+ ImageScience.with_image @pix do |img|
128
134
  img.resize(25.2, 25.7) do |thumb|
129
135
  assert thumb.save(@tmppath)
130
136
  end
@@ -141,7 +147,7 @@ class TestImageScience < MiniTest::Unit::TestCase
141
147
 
142
148
  def test_resize_zero
143
149
  assert_raises ArgumentError do
144
- ImageScience.with_image @path do |img|
150
+ ImageScience.with_image @pix do |img|
145
151
  img.resize(0, 25) do |thumb|
146
152
  assert thumb.save(@tmppath)
147
153
  end
@@ -151,7 +157,7 @@ class TestImageScience < MiniTest::Unit::TestCase
151
157
  refute File.exists?(@tmppath)
152
158
 
153
159
  assert_raises ArgumentError do
154
- ImageScience.with_image @path do |img|
160
+ ImageScience.with_image @pix do |img|
155
161
  img.resize(25, 0) do |thumb|
156
162
  assert thumb.save(@tmppath)
157
163
  end
@@ -163,7 +169,7 @@ class TestImageScience < MiniTest::Unit::TestCase
163
169
 
164
170
  def test_resize_negative
165
171
  assert_raises ArgumentError do
166
- ImageScience.with_image @path do |img|
172
+ ImageScience.with_image @pix do |img|
167
173
  img.resize(-25, 25) do |thumb|
168
174
  assert thumb.save(@tmppath)
169
175
  end
@@ -173,7 +179,7 @@ class TestImageScience < MiniTest::Unit::TestCase
173
179
  refute File.exists?(@tmppath)
174
180
 
175
181
  assert_raises ArgumentError do
176
- ImageScience.with_image @path do |img|
182
+ ImageScience.with_image @pix do |img|
177
183
  img.resize(25, -25) do |thumb|
178
184
  assert thumb.save(@tmppath)
179
185
  end
@@ -183,9 +189,12 @@ class TestImageScience < MiniTest::Unit::TestCase
183
189
  refute File.exists?(@tmppath)
184
190
  end
185
191
 
192
+ ##
193
+ # biggie.png is 800 x 600
194
+
186
195
  def test_fit_within_smaller
187
- ImageScience.with_image @path do |img|
188
- img.fit_within(51, 100) do |thumb|
196
+ ImageScience.with_image @biggie do |img|
197
+ img.fit_within(100, 100) do |thumb|
189
198
  assert thumb.save(@tmppath)
190
199
  end
191
200
  end
@@ -194,65 +203,116 @@ class TestImageScience < MiniTest::Unit::TestCase
194
203
 
195
204
  ImageScience.with_image @tmppath do |img|
196
205
  assert_kind_of ImageScience, img
197
- assert_equal 50, img.height
198
- assert_equal 50, img.width
206
+ assert_equal 100, img.width
199
207
  end
200
208
  end
201
209
 
202
- # def test_fit_within_shrinking_x
203
- # max_x = 44
204
- # max_y = 111
205
- #
206
- # ImageScience.with_image @path do |img|
207
- # img.fit_within(max_x, max_y) do |thumb|
208
- # assert thumb.save(@tmppath)
209
- # end
210
- # end
211
- #
212
- # assert File.exists?(@tmppath)
213
- #
214
- # ImageScience.with_image @tmppath do |img|
215
- # assert_kind_of ImageScience, img
216
- # assert img.height <= 50
217
- # assert img.width <= max_x
218
- # end
219
- # end
220
- #
221
- # def test_fit_within_shrinking_y
222
- # max_x = 100
223
- # max_y = 40
224
- #
225
- # ImageScience.with_image @path do |img|
226
- # img.fit_within(max_x, max_y) do |thumb|
227
- # assert thumb.save(@tmppath)
228
- # end
229
- # end
230
- #
231
- # assert File.exists?(@tmppath)
232
- #
233
- # ImageScience.with_image @tmppath do |img|
234
- # assert_kind_of ImageScience, img
235
- # assert img.height <= max_y
236
- # assert img.width <= 50
237
- # end
238
- # end
239
- #
240
- # def test_fit_within_shrinking_both
241
- # max_x = 33
242
- # max_y = 44
243
- #
244
- # ImageScience.with_image @path do |img|
245
- # img.fit_within(max_x, max_y) do |thumb|
246
- # assert thumb.save(@tmppath)
247
- # end
248
- # end
249
- #
250
- # assert File.exists?(@tmppath)
251
- #
252
- # ImageScience.with_image @tmppath do |img|
253
- # assert_kind_of ImageScience, img
254
- # assert img.height <= max_y
255
- # assert img.width <= max_x
256
- # end
257
- # end
210
+ def test_fit_within_shrinking_x
211
+ max_x = 44
212
+ max_y = 111
213
+
214
+ ImageScience.with_image @pix do |img|
215
+ img.fit_within(max_x, max_y) do |thumb|
216
+ assert thumb.save(@tmppath)
217
+ end
218
+ end
219
+
220
+ assert File.exists?(@tmppath)
221
+
222
+ ImageScience.with_image @tmppath do |img|
223
+ assert_kind_of ImageScience, img
224
+ assert img.height <= 50
225
+ assert img.width <= max_x
226
+ end
227
+ end
228
+
229
+ def test_fit_within_shrinking_y
230
+ max_x = 100
231
+ max_y = 40
232
+
233
+ ImageScience.with_image @pix do |img|
234
+ img.fit_within(max_x, max_y) do |thumb|
235
+ assert thumb.save(@tmppath)
236
+ end
237
+ end
238
+
239
+ assert File.exists?(@tmppath)
240
+
241
+ ImageScience.with_image @tmppath do |img|
242
+ assert_kind_of ImageScience, img
243
+ assert img.height <= max_y
244
+ assert img.width <= 50
245
+ end
246
+ end
247
+
248
+ def test_fit_within_shrinking_both
249
+ max_x = 33
250
+ max_y = 44
251
+
252
+ ImageScience.with_image @pix do |img|
253
+ img.fit_within(max_x, max_y) do |thumb|
254
+ assert thumb.save(@tmppath)
255
+ end
256
+ end
257
+
258
+ assert File.exists?(@tmppath)
259
+
260
+ ImageScience.with_image @tmppath do |img|
261
+ assert_kind_of ImageScience, img
262
+ assert img.height <= max_y
263
+ assert img.width <= max_x
264
+ end
265
+ end
266
+
267
+ def test_fit_withins
268
+
269
+ max_x = max_y = 77
270
+ original_x = original_y = 9999
271
+
272
+ [@pix, @biggie, @bearry, @landscape, @portrait].each { |image_name|
273
+
274
+ ImageScience.with_image image_name do |img|
275
+ original_x = img.width
276
+ original_y = img.height
277
+ img.fit_within(max_x, max_y) do |thumb|
278
+ assert thumb.save(@tmppath)
279
+ end
280
+ end
281
+
282
+ assert File.exists?(@tmppath)
283
+
284
+ ImageScience.with_image @tmppath do |img|
285
+ assert_kind_of ImageScience, img
286
+ assert img.height <= max_y
287
+ assert img.width <= max_x
288
+ assert img.height <= original_y
289
+ assert img.width <= original_x
290
+ end
291
+ }
292
+ end
293
+
294
+ def test_thumbnailing
295
+
296
+ max = 77
297
+ original_x = original_y = 9999
298
+
299
+ [@pix, @biggie, @bearry, @landscape, @portrait].each { |image_name|
300
+
301
+ ImageScience.with_image image_name do |img|
302
+ original_x = img.width
303
+ original_y = img.height
304
+ img.thumbnail(max) do |thumb|
305
+ assert thumb.save(@tmppath)
306
+ end
307
+ end
308
+
309
+ assert File.exists?(@tmppath)
310
+
311
+ ImageScience.with_image @tmppath do |img|
312
+ assert_kind_of ImageScience, img
313
+ assert img.height <= max
314
+ assert img.width <= max
315
+ end
316
+ }
317
+ end
258
318
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: g1nn13-image_science
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - jim nist