hcatlin-image_science 1.2.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.
data/History.txt ADDED
@@ -0,0 +1,83 @@
1
+ === 1.2.2 / 2010-08-14
2
+
3
+ * 1 minor bugfix
4
+
5
+ * Fixed integration with Homebrew on OS X
6
+
7
+ === 1.2.1 / 2009-08-14
8
+
9
+ * 2 minor enhancements:
10
+
11
+ * Added luis' patches to make it build properly on windows.
12
+ * with_image now raises on missing/bad files.
13
+
14
+ == 1.2.0 / 2009-06-23
15
+
16
+ * 7 minor enhancements:
17
+
18
+ * Moved quick_thumb to bin/image_science_thumb and properly added.
19
+ * Added -s (square) flag to bin/image_science_thumb
20
+ * Added autorotating on image load. (choonkeat)
21
+ * Added ruby_inline to clean globs
22
+ * Added with_image_from_memory. (sumbach)
23
+ * Switched to minitest.
24
+ * Updated rakefile for now hoe capabilities.
25
+
26
+ * 3 bug fixes:
27
+
28
+ * Check and convert to 24 BPP if save type is jpg. Caused by 32bpp png to jpg.
29
+ * Fixed 1.9isms
30
+ * Fixed BMP support. Tweaked whitespace.
31
+
32
+ == 1.1.3 / 2007-05-30
33
+
34
+ * 2 minor enhancements:
35
+
36
+ * Added quick_thumb as an example to look at.
37
+ * Error handler doesn't raise by default. Raises if $DEBUG==true.
38
+
39
+ == 1.1.2 / 2007-04-18
40
+
41
+ * 2 bug fixes:
42
+
43
+ * reports bad height/width values for resize
44
+ * explicitly removes ICC color profiles from PNGs (bug in freeimage).
45
+
46
+ == 1.1.1 / 2007-03-08
47
+
48
+ * 5 minor enhancements:
49
+
50
+ * Added error handler that raises with information about what went wrong.
51
+ * thumbnail is now pure ruby, everything now uses resize.
52
+ * Produces cleaner JPEG files, with a small cost to file size/speed.
53
+ * resize now uses Catmull-Rom spline filter for better quality.
54
+ * resize copies existing ICC Profile to thumbnail, producing better color.
55
+ * ICC Profile NOT copied for PNG as it seems to be buggy.
56
+
57
+ * 1 bug fix:
58
+
59
+ * Fixed rdoc
60
+
61
+ == 1.1.0 / 2007-01-05
62
+
63
+ * 3 major enhancements:
64
+
65
+ * Added resize(width, height)
66
+ * Added save(path)
67
+ * All thumbnail and resize methods yield instead of saving directly.
68
+
69
+ * 1 minor enhancement:
70
+
71
+ * Will now try to use FreeImage from ports if /opt/local exists.
72
+
73
+ * 2 bug fixes:
74
+
75
+ * Fixed the linker issue on PPC.
76
+ * Rakefile will now clean the image files created by bench.rb
77
+
78
+ == 1.0.0 / 2006-12-01
79
+
80
+ * 1 major enhancement
81
+
82
+ * Birthday!
83
+
data/Manifest.txt ADDED
@@ -0,0 +1,9 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ bench.rb
6
+ bin/image_science_thumb
7
+ lib/image_science.rb
8
+ test/pix.png
9
+ test/test_image_science.rb
data/README.txt ADDED
@@ -0,0 +1,66 @@
1
+ = ImageScience
2
+
3
+ * http://seattlerb.rubyforge.org/ImageScience.html
4
+ * http://rubyforge.org/projects/seattlerb
5
+
6
+ == DESCRIPTION:
7
+
8
+ ImageScience is a clean and happy Ruby library that generates
9
+ thumbnails -- and kicks the living crap out of RMagick. Oh, and it
10
+ doesn't leak memory like a sieve. :)
11
+
12
+ For more information including build steps, see http://seattlerb.rubyforge.org/
13
+
14
+ == FEATURES/PROBLEMS:
15
+
16
+ * Glorious graphics manipulation magi... errr, SCIENCE! in less than 200 LoC!
17
+ * Supports square and proportional thumbnails, as well as arbitrary resizes.
18
+ * Pretty much any graphics format you could want. No really.
19
+
20
+ == SYNOPSYS:
21
+
22
+ ImageScience.with_image(file) do |img|
23
+ img.cropped_thumbnail(100) do |thumb|
24
+ thumb.save "#{file}_cropped.png"
25
+ end
26
+
27
+ img.thumbnail(100) do |thumb|
28
+ thumb.save "#{file}_thumb.png"
29
+ end
30
+ end
31
+
32
+ == REQUIREMENTS:
33
+
34
+ * FreeImage
35
+ * ImageScience
36
+
37
+ == INSTALL:
38
+
39
+ * Download and install FreeImage. See notes at url above.
40
+ * sudo gem install -y image_science
41
+ * see http://seattlerb.rubyforge.org/ImageScience.html for more info.
42
+
43
+ == LICENSE:
44
+
45
+ (The MIT License)
46
+
47
+ Copyright (c) 2006-2009 Ryan Davis, Seattle.rb
48
+
49
+ Permission is hereby granted, free of charge, to any person obtaining
50
+ a copy of this software and associated documentation files (the
51
+ 'Software'), to deal in the Software without restriction, including
52
+ without limitation the rights to use, copy, modify, merge, publish,
53
+ distribute, sublicense, and/or sell copies of the Software, and to
54
+ permit persons to whom the Software is furnished to do so, subject to
55
+ the following conditions:
56
+
57
+ The above copyright notice and this permission notice shall be
58
+ included in all copies or substantial portions of the Software.
59
+
60
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
61
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
62
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
63
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
64
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
65
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
66
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ Hoe.add_include_dirs("../../RubyInline/dev/lib",
7
+ "../../ZenTest/dev/lib")
8
+
9
+ Hoe.plugin :seattlerb
10
+ Hoe.plugin :inline
11
+
12
+ Hoe.spec 'hcatlin-image_science' do
13
+ developer 'Ryan Davis', 'ryand-ruby@zenspider.com'
14
+
15
+ self.rubyforge_name = 'seattlerb'
16
+
17
+ clean_globs << 'blah*png' << 'images/*_thumb.*'
18
+ end
19
+
20
+ # vim: syntax=Ruby
data/bench.rb ADDED
@@ -0,0 +1,63 @@
1
+ #!/usr/local/bin/ruby -w
2
+
3
+ require 'benchmark'
4
+ require 'rubygems'
5
+ require 'image_science'
6
+
7
+ max = (ARGV.shift || 100).to_i
8
+ ext = ARGV.shift || "png"
9
+
10
+ file = "blah_big.#{ext}"
11
+
12
+ if RUBY_PLATFORM =~ /darwin/ then
13
+ # how fucking cool is this???
14
+ puts "taking screenshot for thumbnailing benchmarks"
15
+ system "screencapture -SC #{file}"
16
+ else
17
+ abort "You need to plonk down #{file} or buy a mac"
18
+ end unless test ?f, "#{file}"
19
+
20
+ ImageScience.with_image(file.sub(/#{ext}$/, 'png')) do |img|
21
+ img.save(file)
22
+ end if ext != "png"
23
+
24
+ puts "# of iterations = #{max}"
25
+ Benchmark::bm(20) do |x|
26
+ x.report("null_time") {
27
+ for i in 0..max do
28
+ # do nothing
29
+ end
30
+ }
31
+
32
+ x.report("cropped") {
33
+ for i in 0..max do
34
+ ImageScience.with_image(file) do |img|
35
+ img.cropped_thumbnail(100) do |thumb|
36
+ thumb.save("blah_cropped.#{ext}")
37
+ end
38
+ end
39
+ end
40
+ }
41
+
42
+ x.report("proportional") {
43
+ for i in 0..max do
44
+ ImageScience.with_image(file) do |img|
45
+ img.thumbnail(100) do |thumb|
46
+ thumb.save("blah_thumb.#{ext}")
47
+ end
48
+ end
49
+ end
50
+ }
51
+
52
+ x.report("resize") {
53
+ for i in 0..max do
54
+ ImageScience.with_image(file) do |img|
55
+ img.resize(200, 200) do |resize|
56
+ resize.save("blah_resize.#{ext}")
57
+ end
58
+ end
59
+ end
60
+ }
61
+ end
62
+
63
+ # File.unlink(*Dir["blah*#{ext}"])
@@ -0,0 +1,31 @@
1
+ #!/usr/local/bin/ruby -ws
2
+
3
+ $s ||= false
4
+
5
+ abort "#{File.basename $0} max_length files..." unless ARGV.size > 1
6
+
7
+ require 'rubygems'
8
+ require 'image_science'
9
+
10
+ max_length = ARGV.shift.to_i
11
+
12
+ msg = $s ? :cropped_thumbnail : :thumbnail
13
+
14
+ ARGV.each do |file|
15
+ begin
16
+ result = ImageScience.with_image file do |img|
17
+ begin
18
+ img.send(msg, max_length) do |thumb|
19
+ # add _thumb and switch from gif to png. Really. gif just sucks.
20
+ out = file.sub(/(\.[^\.]+)$/, '_thumb\1').sub(/gif$/, 'png')
21
+ thumb.save(out)
22
+ end
23
+ rescue => e
24
+ warn "Exception thumbnailing #{file}: #{e}"
25
+ end
26
+ end
27
+ p file => result
28
+ rescue => e
29
+ warn "Exception opening #{file}: #{e}"
30
+ end
31
+ end
@@ -0,0 +1,295 @@
1
+ #!/usr/local/bin/ruby -w
2
+
3
+ require 'rubygems'
4
+ require 'inline'
5
+
6
+ ##
7
+ # Provides a clean and simple API to generate thumbnails using
8
+ # FreeImage as the underlying mechanism.
9
+ #
10
+ # For more information or if you have build issues with FreeImage, see
11
+ # http://seattlerb.rubyforge.org/ImageScience.html
12
+
13
+ class ImageScience
14
+ VERSION = '1.2.2'
15
+
16
+ ##
17
+ # The top-level image loader opens +path+ and then yields the image.
18
+
19
+ def self.with_image(path) # :yields: image
20
+ end
21
+
22
+ ##
23
+ # The top-level image loader, opens an image from the string +data+ and then yields the image.
24
+
25
+ def self.with_image_from_memory(data) # :yields: image
26
+ end
27
+
28
+ ##
29
+ # Crops an image to +left+, +top+, +right+, and +bottom+ and then
30
+ # yields the new image.
31
+
32
+ def with_crop(left, top, right, bottom) # :yields: image
33
+ end
34
+
35
+ ##
36
+ # Returns the width of the image, in pixels.
37
+
38
+ def width; end
39
+
40
+ ##
41
+ # Returns the height of the image, in pixels.
42
+
43
+ def height; end
44
+
45
+ ##
46
+ # Saves the image out to +path+. Changing the file extension will
47
+ # convert the file type to the appropriate format.
48
+
49
+ def save(path); end
50
+
51
+ ##
52
+ # Resizes the image to +width+ and +height+ using a cubic-bspline
53
+ # filter and yields the new image.
54
+
55
+ def resize(width, height) # :yields: image
56
+ end
57
+
58
+ ##
59
+ # Creates a proportional thumbnail of the image scaled so its longest
60
+ # edge is resized to +size+ and yields the new image.
61
+
62
+ def thumbnail(size) # :yields: image
63
+ w, h = width, height
64
+ scale = size.to_f / (w > h ? w : h)
65
+
66
+ self.resize((w * scale).to_i, (h * scale).to_i) do |image|
67
+ yield image
68
+ end
69
+ end
70
+
71
+ ##
72
+ # Creates a square thumbnail of the image cropping the longest edge
73
+ # to match the shortest edge, resizes to +size+, and yields the new
74
+ # image.
75
+
76
+ def cropped_thumbnail(size) # :yields: image
77
+ w, h = width, height
78
+ l, t, r, b, half = 0, 0, w, h, (w - h).abs / 2
79
+
80
+ l, r = half, half + h if w > h
81
+ t, b = half, half + w if h > w
82
+
83
+ with_crop(l, t, r, b) do |img|
84
+ img.thumbnail(size) do |thumb|
85
+ yield thumb
86
+ end
87
+ end
88
+ end
89
+
90
+ inline do |builder|
91
+ ["/opt/local", "/usr/local"].each do |library_directory|
92
+ if test ?d, "#{library_directory}/include" then
93
+ builder.add_compile_flags "-I#{library_directory}/include"
94
+ builder.add_link_flags "-L#{library_directory}/lib"
95
+ end
96
+ end
97
+
98
+ builder.add_link_flags "-lfreeimage"
99
+ unless RUBY_PLATFORM =~ /mswin/
100
+ builder.add_link_flags "-lfreeimage"
101
+ # TODO: detect PPC
102
+ builder.add_link_flags "-lstdc++" # only needed on PPC for some reason
103
+ else
104
+ builder.add_link_flags "freeimage.lib"
105
+ end
106
+ builder.include '"FreeImage.h"'
107
+
108
+ builder.prefix <<-"END"
109
+ #define GET_BITMAP(name) Data_Get_Struct(self, FIBITMAP, (name)); if (!(name)) rb_raise(rb_eTypeError, "Bitmap has already been freed");
110
+ END
111
+
112
+ builder.prefix <<-"END"
113
+ VALUE unload(VALUE self) {
114
+ FIBITMAP *bitmap;
115
+ GET_BITMAP(bitmap);
116
+
117
+ FreeImage_Unload(bitmap);
118
+ DATA_PTR(self) = NULL;
119
+ return Qnil;
120
+ }
121
+ END
122
+
123
+ builder.prefix <<-"END"
124
+ VALUE wrap_and_yield(FIBITMAP *image, VALUE self, FREE_IMAGE_FORMAT fif) {
125
+ unsigned int self_is_class = rb_type(self) == T_CLASS;
126
+ VALUE klass = self_is_class ? self : CLASS_OF(self);
127
+ VALUE type = self_is_class ? INT2FIX(fif) : rb_iv_get(self, "@file_type");
128
+ VALUE obj = Data_Wrap_Struct(klass, NULL, NULL, image);
129
+ rb_iv_set(obj, "@file_type", type);
130
+ return rb_ensure(rb_yield, obj, unload, obj);
131
+ }
132
+ END
133
+
134
+ builder.prefix <<-"END"
135
+ void copy_icc_profile(VALUE self, FIBITMAP *from, FIBITMAP *to) {
136
+ FREE_IMAGE_FORMAT fif = FIX2INT(rb_iv_get(self, "@file_type"));
137
+ if (fif != FIF_PNG && FreeImage_FIFSupportsICCProfiles(fif)) {
138
+ FIICCPROFILE *profile = FreeImage_GetICCProfile(from);
139
+ if (profile && profile->data) {
140
+ FreeImage_CreateICCProfile(to, profile->data, profile->size);
141
+ }
142
+ }
143
+ }
144
+ END
145
+
146
+ builder.prefix <<-"END"
147
+ void FreeImageErrorHandler(FREE_IMAGE_FORMAT fif, const char *message) {
148
+ rb_raise(rb_eRuntimeError,
149
+ "FreeImage exception for type %s: %s",
150
+ (fif == FIF_UNKNOWN) ? "???" : FreeImage_GetFormatFromFIF(fif),
151
+ message);
152
+ }
153
+ END
154
+
155
+ builder.add_to_init "FreeImage_SetOutputMessage(FreeImageErrorHandler);"
156
+
157
+ builder.c_singleton <<-"END"
158
+ VALUE with_image(char * input) {
159
+ FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
160
+ int flags;
161
+
162
+ fif = FreeImage_GetFileType(input, 0);
163
+ if (fif == FIF_UNKNOWN) fif = FreeImage_GetFIFFromFilename(input);
164
+ if ((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) {
165
+ FIBITMAP *bitmap;
166
+ VALUE result = Qnil;
167
+ flags = fif == FIF_JPEG ? JPEG_ACCURATE : 0;
168
+ if (bitmap = FreeImage_Load(fif, input, flags)) {
169
+ FITAG *tagValue = NULL;
170
+ FreeImage_GetMetadata(FIMD_EXIF_MAIN, bitmap, "Orientation", &tagValue);
171
+ switch (tagValue == NULL ? 0 : *((short *) FreeImage_GetTagValue(tagValue))) {
172
+ case 6:
173
+ bitmap = FreeImage_RotateClassic(bitmap, 270);
174
+ break;
175
+ case 3:
176
+ bitmap = FreeImage_RotateClassic(bitmap, 180);
177
+ break;
178
+ case 8:
179
+ bitmap = FreeImage_RotateClassic(bitmap, 90);
180
+ break;
181
+ default:
182
+ break;
183
+ }
184
+
185
+ result = wrap_and_yield(bitmap, self, fif);
186
+ }
187
+ return result;
188
+ }
189
+ rb_raise(rb_eTypeError, "Unknown file format");
190
+ }
191
+ END
192
+
193
+ builder.c_singleton <<-"END"
194
+ VALUE with_image_from_memory(VALUE image_data) {
195
+ FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
196
+
197
+ Check_Type(image_data, T_STRING);
198
+ BYTE *image_data_ptr = (BYTE*)RSTRING_PTR(image_data);
199
+ DWORD image_data_length = RSTRING_LEN(image_data);
200
+ FIMEMORY *stream = FreeImage_OpenMemory(image_data_ptr, image_data_length);
201
+
202
+ if (NULL == stream) {
203
+ rb_raise(rb_eTypeError, "Unable to open image_data");
204
+ }
205
+
206
+ fif = FreeImage_GetFileTypeFromMemory(stream, 0);
207
+ if ((fif == FIF_UNKNOWN) || !FreeImage_FIFSupportsReading(fif)) {
208
+ rb_raise(rb_eTypeError, "Unknown file format");
209
+ }
210
+
211
+ FIBITMAP *bitmap = NULL;
212
+ VALUE result = Qnil;
213
+ int flags = fif == FIF_JPEG ? JPEG_ACCURATE : 0;
214
+ bitmap = FreeImage_LoadFromMemory(fif, stream, flags);
215
+ FreeImage_CloseMemory(stream);
216
+ if (bitmap) {
217
+ result = wrap_and_yield(bitmap, self, fif);
218
+ }
219
+ return result;
220
+ }
221
+ END
222
+
223
+ builder.c <<-"END"
224
+ VALUE with_crop(int l, int t, int r, int b) {
225
+ FIBITMAP *copy, *bitmap;
226
+ VALUE result = Qnil;
227
+ GET_BITMAP(bitmap);
228
+
229
+ if (copy = FreeImage_Copy(bitmap, l, t, r, b)) {
230
+ copy_icc_profile(self, bitmap, copy);
231
+ result = wrap_and_yield(copy, self, 0);
232
+ }
233
+ return result;
234
+ }
235
+ END
236
+
237
+ builder.c <<-"END"
238
+ int height() {
239
+ FIBITMAP *bitmap;
240
+ GET_BITMAP(bitmap);
241
+
242
+ return FreeImage_GetHeight(bitmap);
243
+ }
244
+ END
245
+
246
+ builder.c <<-"END"
247
+ int width() {
248
+ FIBITMAP *bitmap;
249
+ GET_BITMAP(bitmap);
250
+
251
+ return FreeImage_GetWidth(bitmap);
252
+ }
253
+ END
254
+
255
+ builder.c <<-"END"
256
+ VALUE resize(long w, long h) {
257
+ FIBITMAP *bitmap, *image;
258
+ if (w <= 0) rb_raise(rb_eArgError, "Width <= 0");
259
+ if (h <= 0) rb_raise(rb_eArgError, "Height <= 0");
260
+ GET_BITMAP(bitmap);
261
+ image = FreeImage_Rescale(bitmap, w, h, FILTER_CATMULLROM);
262
+ if (image) {
263
+ copy_icc_profile(self, bitmap, image);
264
+ return wrap_and_yield(image, self, 0);
265
+ }
266
+ return Qnil;
267
+ }
268
+ END
269
+
270
+ builder.c <<-"END"
271
+ VALUE save(char * output) {
272
+ int flags;
273
+ FIBITMAP *bitmap;
274
+ FREE_IMAGE_FORMAT fif = FreeImage_GetFIFFromFilename(output);
275
+ if (fif == FIF_UNKNOWN) fif = FIX2INT(rb_iv_get(self, "@file_type"));
276
+ if ((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsWriting(fif)) {
277
+ GET_BITMAP(bitmap);
278
+ flags = fif == FIF_JPEG ? JPEG_QUALITYSUPERB : 0;
279
+ BOOL result = 0, unload = 0;
280
+
281
+ if (fif == FIF_PNG) FreeImage_DestroyICCProfile(bitmap);
282
+ if (fif == FIF_JPEG && FreeImage_GetBPP(bitmap) != 24)
283
+ bitmap = FreeImage_ConvertTo24Bits(bitmap), unload = 1; // sue me
284
+
285
+ result = FreeImage_Save(fif, bitmap, output, flags);
286
+
287
+ if (unload) FreeImage_Unload(bitmap);
288
+
289
+ return result ? Qtrue : Qfalse;
290
+ }
291
+ rb_raise(rb_eTypeError, "Unknown file format");
292
+ }
293
+ END
294
+ end
295
+ end
data/test/pix.png ADDED
Binary file
@@ -0,0 +1,160 @@
1
+ dir = File.expand_path "~/.ruby_inline"
2
+ if test ?d, dir then
3
+ require 'fileutils'
4
+ puts "nuking #{dir}"
5
+ # force removal, Windoze is bitching at me, something to hunt later...
6
+ FileUtils.rm_r dir, :force => true
7
+ end
8
+
9
+ require 'rubygems'
10
+ require 'minitest/unit'
11
+ require 'minitest/autorun' if $0 == __FILE__
12
+ require 'image_science'
13
+
14
+ class TestImageScience < MiniTest::Unit::TestCase
15
+ def setup
16
+ @path = 'test/pix.png'
17
+ @tmppath = 'test/pix-tmp.png'
18
+ @h = @w = 50
19
+ end
20
+
21
+ def teardown
22
+ File.unlink @tmppath if File.exist? @tmppath
23
+ end
24
+
25
+ def test_class_with_image
26
+ ImageScience.with_image @path do |img|
27
+ assert_kind_of ImageScience, img
28
+ assert_equal @h, img.height
29
+ assert_equal @w, img.width
30
+ assert img.save(@tmppath)
31
+ end
32
+
33
+ assert File.exists?(@tmppath)
34
+
35
+ ImageScience.with_image @tmppath do |img|
36
+ assert_kind_of ImageScience, img
37
+ assert_equal @h, img.height
38
+ assert_equal @w, img.width
39
+ end
40
+ end
41
+
42
+ def test_class_with_image_missing
43
+ assert_raises TypeError do
44
+ ImageScience.with_image @path + "nope" do |img|
45
+ flunk
46
+ end
47
+ end
48
+ end
49
+
50
+ def test_class_with_image_missing_with_img_extension
51
+ assert_raises RuntimeError do
52
+ assert_nil ImageScience.with_image("nope#{@path}") do |img|
53
+ flunk
54
+ end
55
+ end
56
+ end
57
+
58
+ def test_class_with_image_from_memory
59
+ data = File.new(@path).binmode.read
60
+
61
+ ImageScience.with_image_from_memory data do |img|
62
+ assert_kind_of ImageScience, img
63
+ assert_equal @h, img.height
64
+ assert_equal @w, img.width
65
+ assert img.save(@tmppath)
66
+ end
67
+
68
+ assert File.exists?(@tmppath)
69
+
70
+ ImageScience.with_image @tmppath do |img|
71
+ assert_kind_of ImageScience, img
72
+ assert_equal @h, img.height
73
+ assert_equal @w, img.width
74
+ end
75
+ end
76
+
77
+ def test_class_with_image_from_memory_empty_string
78
+ assert_raises TypeError do
79
+ ImageScience.with_image_from_memory "" do |img|
80
+ flunk
81
+ end
82
+ end
83
+ end
84
+
85
+ def test_resize
86
+ ImageScience.with_image @path do |img|
87
+ img.resize(25, 25) do |thumb|
88
+ assert thumb.save(@tmppath)
89
+ end
90
+ end
91
+
92
+ assert File.exists?(@tmppath)
93
+
94
+ ImageScience.with_image @tmppath do |img|
95
+ assert_kind_of ImageScience, img
96
+ assert_equal 25, img.height
97
+ assert_equal 25, img.width
98
+ end
99
+ end
100
+
101
+ def test_resize_floats
102
+ ImageScience.with_image @path do |img|
103
+ img.resize(25.2, 25.7) do |thumb|
104
+ assert thumb.save(@tmppath)
105
+ end
106
+ end
107
+
108
+ assert File.exists?(@tmppath)
109
+
110
+ ImageScience.with_image @tmppath do |img|
111
+ assert_kind_of ImageScience, img
112
+ assert_equal 25, img.height
113
+ assert_equal 25, img.width
114
+ end
115
+ end
116
+
117
+ def test_resize_zero
118
+ assert_raises ArgumentError do
119
+ ImageScience.with_image @path do |img|
120
+ img.resize(0, 25) do |thumb|
121
+ assert thumb.save(@tmppath)
122
+ end
123
+ end
124
+ end
125
+
126
+ refute File.exists?(@tmppath)
127
+
128
+ assert_raises ArgumentError do
129
+ ImageScience.with_image @path do |img|
130
+ img.resize(25, 0) do |thumb|
131
+ assert thumb.save(@tmppath)
132
+ end
133
+ end
134
+ end
135
+
136
+ refute File.exists?(@tmppath)
137
+ end
138
+
139
+ def test_resize_negative
140
+ assert_raises ArgumentError do
141
+ ImageScience.with_image @path do |img|
142
+ img.resize(-25, 25) do |thumb|
143
+ assert thumb.save(@tmppath)
144
+ end
145
+ end
146
+ end
147
+
148
+ refute File.exists?(@tmppath)
149
+
150
+ assert_raises ArgumentError do
151
+ ImageScience.with_image @path do |img|
152
+ img.resize(25, -25) do |thumb|
153
+ assert thumb.save(@tmppath)
154
+ end
155
+ end
156
+ end
157
+
158
+ refute File.exists?(@tmppath)
159
+ end
160
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hcatlin-image_science
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 2
8
+ - 2
9
+ version: 1.2.2
10
+ platform: ruby
11
+ authors:
12
+ - Ryan Davis
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-12-03 00:00:00 +00:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rubyforge
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 2
30
+ - 0
31
+ - 4
32
+ version: 2.0.4
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: hoe
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 2
45
+ - 7
46
+ - 0
47
+ version: 2.7.0
48
+ type: :development
49
+ version_requirements: *id002
50
+ description: |-
51
+ ImageScience is a clean and happy Ruby library that generates
52
+ thumbnails -- and kicks the living crap out of RMagick. Oh, and it
53
+ doesn't leak memory like a sieve. :)
54
+
55
+ For more information including build steps, see http://seattlerb.rubyforge.org/
56
+ email:
57
+ - ryand-ruby@zenspider.com
58
+ executables:
59
+ - image_science_thumb
60
+ extensions: []
61
+
62
+ extra_rdoc_files:
63
+ - History.txt
64
+ - Manifest.txt
65
+ - README.txt
66
+ files:
67
+ - History.txt
68
+ - Manifest.txt
69
+ - README.txt
70
+ - Rakefile
71
+ - bench.rb
72
+ - bin/image_science_thumb
73
+ - lib/image_science.rb
74
+ - test/pix.png
75
+ - test/test_image_science.rb
76
+ has_rdoc: true
77
+ homepage: http://seattlerb.rubyforge.org/ImageScience.html
78
+ licenses: []
79
+
80
+ post_install_message:
81
+ rdoc_options:
82
+ - --main
83
+ - README.txt
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ segments:
100
+ - 0
101
+ version: "0"
102
+ requirements: []
103
+
104
+ rubyforge_project: seattlerb
105
+ rubygems_version: 1.3.7
106
+ signing_key:
107
+ specification_version: 3
108
+ summary: ImageScience is a clean and happy Ruby library that generates thumbnails -- and kicks the living crap out of RMagick
109
+ test_files:
110
+ - test/test_image_science.rb