image_science 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ == 1.1.2 / 2007-04-18
2
+
3
+ * 2 bug fixes:
4
+ * reports bad height/width values for resize
5
+ * explicitly removes ICC color profiles from PNGs (bug in freeimage).
6
+
1
7
  == 1.1.1 / 2007-03-08
2
8
 
3
9
  * 5 minor enhancements:
data/Manifest.txt CHANGED
@@ -4,3 +4,5 @@ README.txt
4
4
  Rakefile
5
5
  bench.rb
6
6
  lib/image_science.rb
7
+ test/pix.png
8
+ test/test_image_science.rb
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.1.1'
14
+ VERSION = '1.1.2'
15
15
 
16
16
  ##
17
17
  # The top-level image loader opens +path+ and then yields the image.
@@ -181,11 +181,16 @@ class ImageScience
181
181
  END
182
182
 
183
183
  builder.c <<-"END"
184
- VALUE resize(int w, int h) {
184
+ VALUE resize(long w, long h) {
185
+ if (w <= 0) rb_raise(rb_eArgError, "Width <= 0");
186
+ if (h <= 0) rb_raise(rb_eArgError, "Height <= 0");
185
187
  GET_BITMAP(bitmap);
186
188
  FIBITMAP *image = FreeImage_Rescale(bitmap, w, h, FILTER_CATMULLROM);
187
- copy_icc_profile(self, bitmap, image);
188
- return wrap_and_yield(image, self, 0);
189
+ if (image) {
190
+ copy_icc_profile(self, bitmap, image);
191
+ return wrap_and_yield(image, self, 0);
192
+ }
193
+ return Qnil;
189
194
  }
190
195
  END
191
196
 
@@ -196,6 +201,7 @@ class ImageScience
196
201
  if ((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsWriting(fif)) {
197
202
  GET_BITMAP(bitmap);
198
203
  int flags = fif == FIF_JPEG ? JPEG_QUALITYSUPERB : 0;
204
+ if (fif == FIF_PNG) FreeImage_DestroyICCProfile(bitmap);
199
205
  return FreeImage_Save(fif, bitmap, output, flags) ? Qtrue : Qfalse;
200
206
  }
201
207
  rb_raise(rb_eTypeError, "Unknown file format");
data/test/pix.png ADDED
Binary file
@@ -0,0 +1,124 @@
1
+ require 'test/unit/testcase'
2
+ require 'test/unit' if $0 == __FILE__
3
+ require 'image_science'
4
+
5
+ class TestImageScience < Test::Unit::TestCase
6
+ def deny x; assert ! x; end
7
+
8
+ def setup
9
+ @path = 'test/pix.png'
10
+ @tmppath = 'test/pix-tmp.png'
11
+ @h = @w = 50
12
+ end
13
+
14
+ def teardown
15
+ File.unlink @tmppath if File.exist? @tmppath
16
+ end
17
+
18
+ def test_class_with_image
19
+ ImageScience.with_image @path do |img|
20
+ assert_kind_of ImageScience, img
21
+ assert_equal @h, img.height
22
+ assert_equal @w, img.width
23
+ assert img.save(@tmppath)
24
+ end
25
+
26
+ assert File.exists?(@tmppath)
27
+
28
+ ImageScience.with_image @tmppath do |img|
29
+ assert_kind_of ImageScience, img
30
+ assert_equal @h, img.height
31
+ assert_equal @w, img.width
32
+ end
33
+ end
34
+
35
+ def test_class_with_image_missing
36
+ assert_raises TypeError do
37
+ ImageScience.with_image @path + "nope" do |img|
38
+ flunk
39
+ end
40
+ end
41
+ end
42
+
43
+ def test_class_with_image_missing_with_img_extension
44
+ assert_nil ImageScience.with_image("nope#{@path}") do |img|
45
+ flunk
46
+ end
47
+ end
48
+
49
+ def test_resize
50
+ ImageScience.with_image @path do |img|
51
+ img.resize(25, 25) do |thumb|
52
+ assert thumb.save(@tmppath)
53
+ end
54
+ end
55
+
56
+ assert File.exists?(@tmppath)
57
+
58
+ ImageScience.with_image @tmppath do |img|
59
+ assert_kind_of ImageScience, img
60
+ assert_equal 25, img.height
61
+ assert_equal 25, img.width
62
+ end
63
+ end
64
+
65
+ def test_resize_floats
66
+ ImageScience.with_image @path do |img|
67
+ img.resize(25.2, 25.7) do |thumb|
68
+ assert thumb.save(@tmppath)
69
+ end
70
+ end
71
+
72
+ assert File.exists?(@tmppath)
73
+
74
+ ImageScience.with_image @tmppath do |img|
75
+ assert_kind_of ImageScience, img
76
+ assert_equal 25, img.height
77
+ assert_equal 25, img.width
78
+ end
79
+ end
80
+
81
+ def test_resize_zero
82
+ assert_raises ArgumentError do
83
+ ImageScience.with_image @path do |img|
84
+ img.resize(0, 25) do |thumb|
85
+ assert thumb.save(@tmppath)
86
+ end
87
+ end
88
+ end
89
+
90
+ deny File.exists?(@tmppath)
91
+
92
+ assert_raises ArgumentError do
93
+ ImageScience.with_image @path do |img|
94
+ img.resize(25, 0) do |thumb|
95
+ assert thumb.save(@tmppath)
96
+ end
97
+ end
98
+ end
99
+
100
+ deny File.exists?(@tmppath)
101
+ end
102
+
103
+ def test_resize_negative
104
+ assert_raises ArgumentError do
105
+ ImageScience.with_image @path do |img|
106
+ img.resize(-25, 25) do |thumb|
107
+ assert thumb.save(@tmppath)
108
+ end
109
+ end
110
+ end
111
+
112
+ deny File.exists?(@tmppath)
113
+
114
+ assert_raises ArgumentError do
115
+ ImageScience.with_image @path do |img|
116
+ img.resize(25, -25) do |thumb|
117
+ assert thumb.save(@tmppath)
118
+ end
119
+ end
120
+ end
121
+
122
+ deny File.exists?(@tmppath)
123
+ end
124
+ end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0.9
3
3
  specification_version: 1
4
4
  name: image_science
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.1.1
7
- date: 2007-03-08 00:00:00 -08:00
6
+ version: 1.1.2
7
+ date: 2007-04-18 00:00:00 -04:00
8
8
  summary: ImageScience is a clean and happy Ruby library that generates thumbnails -- and kicks the living crap out of RMagick.
9
9
  require_paths:
10
10
  - lib
@@ -35,8 +35,10 @@ files:
35
35
  - Rakefile
36
36
  - bench.rb
37
37
  - lib/image_science.rb
38
- test_files: []
39
-
38
+ - test/pix.png
39
+ - test/test_image_science.rb
40
+ test_files:
41
+ - test/test_image_science.rb
40
42
  rdoc_options: []
41
43
 
42
44
  extra_rdoc_files: []