image_science 1.2.6 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/History.txt +10 -0
- data/Rakefile +2 -0
- data/lib/image_science.rb +56 -38
- data/test/test_image_science.rb +28 -9
- metadata +15 -31
- metadata.gz.sig +0 -0
- data/.gemtest +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb44497f07164016d9a369ec83065816b3a7d837
|
4
|
+
data.tar.gz: 6c5fdaa3fd0a82bfb2decd4542601ab063dac965
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26db89c63f7a24c5b72fadc9eae287c171fe5c81e9cb5cde0af95bbffdcb92dcffb4545e3219581d940ae74845f7a7f2df617210a14161c33c2afa23e0d7bbf0
|
7
|
+
data.tar.gz: a3710d72afbe244c133abbde96f9794e750132c6f641cb00a3c212103447aed3f3c46c503a635000d041532642bde4d0e09936d7df3dde20575132d2dc9f35ba
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/History.txt
CHANGED
data/Rakefile
CHANGED
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.
|
14
|
+
VERSION = '1.3.0'
|
15
15
|
|
16
16
|
##
|
17
17
|
# The top-level image loader opens +path+ and then yields the image.
|
@@ -52,6 +52,11 @@ class ImageScience
|
|
52
52
|
#
|
53
53
|
# :method: resize
|
54
54
|
|
55
|
+
##
|
56
|
+
# Rotate the image to +angle+. Limited to 45 degree skewing only.
|
57
|
+
#
|
58
|
+
# :method: rotate
|
59
|
+
|
55
60
|
##
|
56
61
|
# Creates a proportional thumbnail of the image scaled so its longest
|
57
62
|
# edge is resized to +size+ and yields the new image.
|
@@ -105,7 +110,8 @@ class ImageScience
|
|
105
110
|
builder.prefix <<-"END"
|
106
111
|
#define GET_BITMAP(name) Data_Get_Struct(self, FIBITMAP, (name)); if (!(name)) rb_raise(rb_eTypeError, "Bitmap has already been freed");
|
107
112
|
static ID err_key; /* used as thread-local key */
|
108
|
-
static void
|
113
|
+
static void clear_error(void);
|
114
|
+
static void raise_error(void);
|
109
115
|
END
|
110
116
|
|
111
117
|
builder.prefix <<-"END"
|
@@ -115,29 +121,19 @@ class ImageScience
|
|
115
121
|
|
116
122
|
FreeImage_Unload(bitmap);
|
117
123
|
DATA_PTR(self) = NULL;
|
118
|
-
|
124
|
+
clear_error();
|
119
125
|
return Qnil;
|
120
126
|
}
|
121
127
|
END
|
122
128
|
|
123
129
|
builder.prefix <<-"END"
|
124
|
-
static VALUE raise_or_yield(VALUE obj) {
|
125
|
-
/*
|
126
|
-
* check for FreeImage routines which may warn or error out,
|
127
|
-
* do not run user code if there are warnings/errors here:
|
128
|
-
*/
|
129
|
-
raise_deferred();
|
130
|
-
|
131
|
-
return rb_yield(obj);
|
132
|
-
}
|
133
|
-
|
134
130
|
VALUE wrap_and_yield(FIBITMAP *image, VALUE self, FREE_IMAGE_FORMAT fif) {
|
135
131
|
unsigned int self_is_class = rb_type(self) == T_CLASS;
|
136
132
|
VALUE klass = self_is_class ? self : CLASS_OF(self);
|
137
133
|
VALUE type = self_is_class ? INT2FIX(fif) : rb_iv_get(self, "@file_type");
|
138
134
|
VALUE obj = Data_Wrap_Struct(klass, NULL, NULL, image);
|
139
135
|
rb_iv_set(obj, "@file_type", type);
|
140
|
-
return rb_ensure(
|
136
|
+
return rb_ensure(rb_yield, obj, unload, obj);
|
141
137
|
}
|
142
138
|
END
|
143
139
|
|
@@ -169,15 +165,25 @@ class ImageScience
|
|
169
165
|
# do not call this until necessary variables are wrapped up for GC
|
170
166
|
# otherwise there will be leaks
|
171
167
|
builder.prefix <<-"END"
|
172
|
-
static void
|
168
|
+
static void raise_error(void) {
|
173
169
|
VALUE err = rb_thread_local_aref(rb_thread_current(), err_key);
|
174
|
-
if (
|
170
|
+
if (NIL_P(err)) {
|
171
|
+
rb_raise(rb_eRuntimeError, "FreeImage exception");
|
172
|
+
} else {
|
175
173
|
rb_thread_local_aset(rb_thread_current(), err_key, Qnil);
|
176
174
|
rb_raise(rb_eRuntimeError, "%s", StringValueCStr(err));
|
177
175
|
}
|
178
176
|
}
|
179
177
|
END
|
180
178
|
|
179
|
+
builder.prefix <<-"END"
|
180
|
+
static void clear_error(void) {
|
181
|
+
if (!NIL_P(rb_thread_local_aref(rb_thread_current(), err_key))) {
|
182
|
+
rb_thread_local_aset(rb_thread_current(), err_key, Qnil);
|
183
|
+
}
|
184
|
+
}
|
185
|
+
END
|
186
|
+
|
181
187
|
builder.prefix <<-"END"
|
182
188
|
FIBITMAP* ReOrient(FIBITMAP *bitmap) {
|
183
189
|
FITAG *tagValue = NULL;
|
@@ -216,11 +222,11 @@ class ImageScience
|
|
216
222
|
FIBITMAP *bitmap;
|
217
223
|
VALUE result = Qnil;
|
218
224
|
flags = fif == FIF_JPEG ? JPEG_ACCURATE : 0;
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
225
|
+
|
226
|
+
if (!(bitmap = FreeImage_Load(fif, input, flags))) raise_error();
|
227
|
+
if (!(bitmap = ReOrient(bitmap))) raise_error();
|
228
|
+
|
229
|
+
result = wrap_and_yield(bitmap, self, fif);
|
224
230
|
return result;
|
225
231
|
}
|
226
232
|
rb_raise(rb_eTypeError, "Unknown file format");
|
@@ -249,17 +255,18 @@ class ImageScience
|
|
249
255
|
|
250
256
|
fif = FreeImage_GetFileTypeFromMemory(stream, 0);
|
251
257
|
if ((fif == FIF_UNKNOWN) || !FreeImage_FIFSupportsReading(fif)) {
|
258
|
+
FreeImage_CloseMemory(stream);
|
252
259
|
rb_raise(rb_eTypeError, "Unknown file format");
|
253
260
|
}
|
254
261
|
|
255
262
|
flags = fif == FIF_JPEG ? JPEG_ACCURATE : 0;
|
256
263
|
bitmap = FreeImage_LoadFromMemory(fif, stream, flags);
|
257
264
|
FreeImage_CloseMemory(stream);
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
265
|
+
|
266
|
+
if (!bitmap) raise_error();
|
267
|
+
if (!(bitmap = ReOrient(bitmap))) raise_error();
|
268
|
+
|
269
|
+
result = wrap_and_yield(bitmap, self, fif);
|
263
270
|
return result;
|
264
271
|
}
|
265
272
|
END
|
@@ -267,15 +274,12 @@ class ImageScience
|
|
267
274
|
builder.c <<-"END"
|
268
275
|
VALUE with_crop(int l, int t, int r, int b) {
|
269
276
|
FIBITMAP *copy, *bitmap;
|
270
|
-
VALUE result = Qnil;
|
271
277
|
GET_BITMAP(bitmap);
|
272
278
|
|
273
|
-
if ((copy = FreeImage_Copy(bitmap, l, t, r, b)))
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
raise_deferred();
|
278
|
-
return result;
|
279
|
+
if (!(copy = FreeImage_Copy(bitmap, l, t, r, b))) raise_error();
|
280
|
+
|
281
|
+
copy_icc_profile(self, bitmap, copy);
|
282
|
+
return wrap_and_yield(copy, self, 0);
|
279
283
|
}
|
280
284
|
END
|
281
285
|
|
@@ -303,12 +307,25 @@ class ImageScience
|
|
303
307
|
if (w <= 0) rb_raise(rb_eArgError, "Width <= 0");
|
304
308
|
if (h <= 0) rb_raise(rb_eArgError, "Height <= 0");
|
305
309
|
GET_BITMAP(bitmap);
|
310
|
+
|
306
311
|
image = FreeImage_Rescale(bitmap, w, h, FILTER_CATMULLROM);
|
312
|
+
if (!image) raise_error();
|
313
|
+
|
314
|
+
copy_icc_profile(self, bitmap, image);
|
315
|
+
return wrap_and_yield(image, self, 0);
|
316
|
+
}
|
317
|
+
END
|
318
|
+
|
319
|
+
builder.c <<-"END"
|
320
|
+
VALUE rotate(int angle) {
|
321
|
+
FIBITMAP *bitmap, *image;
|
322
|
+
if ((angle % 45) != 0) rb_raise(rb_eArgError, "Angle must be 45 degree skew");
|
323
|
+
GET_BITMAP(bitmap);
|
324
|
+
image = FreeImage_RotateClassic(bitmap, angle);
|
307
325
|
if (image) {
|
308
326
|
copy_icc_profile(self, bitmap, image);
|
309
327
|
return wrap_and_yield(image, self, 0);
|
310
328
|
}
|
311
|
-
raise_deferred();
|
312
329
|
return Qnil;
|
313
330
|
}
|
314
331
|
END
|
@@ -325,15 +342,16 @@ class ImageScience
|
|
325
342
|
flags = fif == FIF_JPEG ? JPEG_QUALITYSUPERB : 0;
|
326
343
|
|
327
344
|
if (fif == FIF_PNG) FreeImage_DestroyICCProfile(bitmap);
|
328
|
-
if (fif == FIF_JPEG && FreeImage_GetBPP(bitmap) != 24)
|
345
|
+
if (fif == FIF_JPEG && FreeImage_GetBPP(bitmap) != 24) {
|
329
346
|
bitmap = FreeImage_ConvertTo24Bits(bitmap), unload = 1; // sue me
|
347
|
+
if (!bitmap) raise_error();
|
348
|
+
}
|
330
349
|
|
331
350
|
result = FreeImage_Save(fif, bitmap, output, flags);
|
332
|
-
|
333
351
|
if (unload) FreeImage_Unload(bitmap);
|
352
|
+
if (!result) raise_error();
|
334
353
|
|
335
|
-
|
336
|
-
return result ? Qtrue : Qfalse;
|
354
|
+
return Qtrue;
|
337
355
|
}
|
338
356
|
rb_raise(rb_eTypeError, "Unknown file format");
|
339
357
|
return Qnil;
|
data/test/test_image_science.rb
CHANGED
@@ -30,7 +30,7 @@ class TestImageScience < Minitest::Test
|
|
30
30
|
assert img.save(@tmppath)
|
31
31
|
end
|
32
32
|
|
33
|
-
assert File.
|
33
|
+
assert File.exist?(@tmppath)
|
34
34
|
|
35
35
|
ImageScience.with_image @tmppath do |img|
|
36
36
|
assert_kind_of ImageScience, img
|
@@ -65,7 +65,7 @@ class TestImageScience < Minitest::Test
|
|
65
65
|
assert img.save(@tmppath)
|
66
66
|
end
|
67
67
|
|
68
|
-
assert File.
|
68
|
+
assert File.exist?(@tmppath)
|
69
69
|
|
70
70
|
ImageScience.with_image @tmppath do |img|
|
71
71
|
assert_kind_of ImageScience, img
|
@@ -89,7 +89,7 @@ class TestImageScience < Minitest::Test
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
-
assert File.
|
92
|
+
assert File.exist?(@tmppath)
|
93
93
|
|
94
94
|
ImageScience.with_image @tmppath do |img|
|
95
95
|
assert_kind_of ImageScience, img
|
@@ -105,7 +105,7 @@ class TestImageScience < Minitest::Test
|
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
108
|
-
assert File.
|
108
|
+
assert File.exist?(@tmppath)
|
109
109
|
|
110
110
|
ImageScience.with_image @tmppath do |img|
|
111
111
|
assert_kind_of ImageScience, img
|
@@ -123,7 +123,7 @@ class TestImageScience < Minitest::Test
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
|
-
refute File.
|
126
|
+
refute File.exist?(@tmppath)
|
127
127
|
|
128
128
|
assert_raises ArgumentError do
|
129
129
|
ImageScience.with_image @path do |img|
|
@@ -133,7 +133,7 @@ class TestImageScience < Minitest::Test
|
|
133
133
|
end
|
134
134
|
end
|
135
135
|
|
136
|
-
refute File.
|
136
|
+
refute File.exist?(@tmppath)
|
137
137
|
end
|
138
138
|
|
139
139
|
def test_resize_negative
|
@@ -145,7 +145,7 @@ class TestImageScience < Minitest::Test
|
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
148
|
-
refute File.
|
148
|
+
refute File.exist?(@tmppath)
|
149
149
|
|
150
150
|
assert_raises ArgumentError do
|
151
151
|
ImageScience.with_image @path do |img|
|
@@ -155,7 +155,7 @@ class TestImageScience < Minitest::Test
|
|
155
155
|
end
|
156
156
|
end
|
157
157
|
|
158
|
-
refute File.
|
158
|
+
refute File.exist?(@tmppath)
|
159
159
|
end
|
160
160
|
|
161
161
|
def test_thumbnail
|
@@ -165,7 +165,7 @@ class TestImageScience < Minitest::Test
|
|
165
165
|
end
|
166
166
|
end
|
167
167
|
|
168
|
-
assert File.
|
168
|
+
assert File.exist?(@tmppath)
|
169
169
|
|
170
170
|
ImageScience.with_image @tmppath do |img|
|
171
171
|
assert_kind_of ImageScience, img
|
@@ -188,4 +188,23 @@ class TestImageScience < Minitest::Test
|
|
188
188
|
assert_equal 38, img.width
|
189
189
|
end
|
190
190
|
end
|
191
|
+
|
192
|
+
def test_rotate
|
193
|
+
ImageScience.with_image "test/portrait.jpg" do |image|
|
194
|
+
image.rotate 90 do |img|
|
195
|
+
assert_equal 50, img.width
|
196
|
+
assert_equal 38, img.height
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_rotate_not_45
|
202
|
+
e = assert_raises ArgumentError do
|
203
|
+
ImageScience.with_image "test/portrait.jpg" do |image|
|
204
|
+
image.rotate 44
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
assert_equal 'Angle must be 45 degree skew', e.message
|
209
|
+
end
|
191
210
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: image_science
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Davis
|
@@ -10,9 +10,9 @@ bindir: bin
|
|
10
10
|
cert_chain:
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
|
-
|
13
|
+
MIIDPjCCAiagAwIBAgIBAzANBgkqhkiG9w0BAQUFADBFMRMwEQYDVQQDDApyeWFu
|
14
14
|
ZC1ydWJ5MRkwFwYKCZImiZPyLGQBGRYJemVuc3BpZGVyMRMwEQYKCZImiZPyLGQB
|
15
|
-
|
15
|
+
GRYDY29tMB4XDTE1MDkxOTIwNTEyMloXDTE2MDkxODIwNTEyMlowRTETMBEGA1UE
|
16
16
|
AwwKcnlhbmQtcnVieTEZMBcGCgmSJomT8ixkARkWCXplbnNwaWRlcjETMBEGCgmS
|
17
17
|
JomT8ixkARkWA2NvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALda
|
18
18
|
b9DCgK+627gPJkB6XfjZ1itoOQvpqH1EXScSaba9/S2VF22VYQbXU1xQXL/WzCkx
|
@@ -22,14 +22,14 @@ cert_chain:
|
|
22
22
|
qhtV7HJxNKuPj/JFH0D2cswvzznE/a5FOYO68g+YCuFi5L8wZuuM8zzdwjrWHqSV
|
23
23
|
gBEfoTEGr7Zii72cx+sCAwEAAaM5MDcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAw
|
24
24
|
HQYDVR0OBBYEFEfFe9md/r/tj/Wmwpy+MI8d9k/hMA0GCSqGSIb3DQEBBQUAA4IB
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
25
|
+
AQB+Hx8xUgrpZa4P8H8gR8zme5kISwQrG80MbpqJV6/G3/ZicRFhN5sjwu0uHGue
|
26
|
+
bd9Cymf6oIRwHVarJux2M32T6bL07Hmi07w2QaPc3MnMKB/D46SRZ2JSSGPFRBTc
|
27
|
+
SilobMRoGs/7B15uGFUEnNrCB/ltMqhwwSx1r++UQPfeySHEV9uqu03E5Vb7J37O
|
28
|
+
2Er6PLXHRiYsIycD1LkMi6YnixdITRHmrqJYE2rsjaIfpIehiusVAPHkNf7qbpHq
|
29
|
+
qx3h45R1CAsObX0SQDIT+rRbQrtKz1GHIZTOFYvEJjUY1XmRTZupD3CJ8Q7sDqSy
|
30
|
+
NLq5jm1fq6Y9Uolu3RJbmycf
|
31
31
|
-----END CERTIFICATE-----
|
32
|
-
date:
|
32
|
+
date: 2016-05-16 00:00:00.000000000 Z
|
33
33
|
dependencies:
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: RubyInline
|
@@ -45,20 +45,6 @@ dependencies:
|
|
45
45
|
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '3.9'
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: minitest
|
50
|
-
requirement: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ~>
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '5.2'
|
55
|
-
type: :development
|
56
|
-
prerelease: false
|
57
|
-
version_requirements: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ~>
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '5.2'
|
62
48
|
- !ruby/object:Gem::Dependency
|
63
49
|
name: rdoc
|
64
50
|
requirement: !ruby/object:Gem::Requirement
|
@@ -79,14 +65,14 @@ dependencies:
|
|
79
65
|
requirements:
|
80
66
|
- - ~>
|
81
67
|
- !ruby/object:Gem::Version
|
82
|
-
version: '3.
|
68
|
+
version: '3.15'
|
83
69
|
type: :development
|
84
70
|
prerelease: false
|
85
71
|
version_requirements: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
73
|
- - ~>
|
88
74
|
- !ruby/object:Gem::Version
|
89
|
-
version: '3.
|
75
|
+
version: '3.15'
|
90
76
|
description: |-
|
91
77
|
ImageScience is a clean and happy Ruby library that generates
|
92
78
|
thumbnails -- and kicks the living crap out of RMagick. Oh, and it
|
@@ -103,7 +89,6 @@ extra_rdoc_files:
|
|
103
89
|
- Manifest.txt
|
104
90
|
- README.txt
|
105
91
|
files:
|
106
|
-
- .gemtest
|
107
92
|
- History.txt
|
108
93
|
- Manifest.txt
|
109
94
|
- README.txt
|
@@ -135,11 +120,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
120
|
- !ruby/object:Gem::Version
|
136
121
|
version: '0'
|
137
122
|
requirements: []
|
138
|
-
rubyforge_project:
|
139
|
-
rubygems_version: 2.
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.4.5
|
140
125
|
signing_key:
|
141
126
|
specification_version: 4
|
142
127
|
summary: ImageScience is a clean and happy Ruby library that generates thumbnails
|
143
128
|
-- and kicks the living crap out of RMagick
|
144
|
-
test_files:
|
145
|
-
- test/test_image_science.rb
|
129
|
+
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|
data/.gemtest
DELETED
File without changes
|