image_voodoo 0.3 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/image_voodoo +1 -1
- data/lib/image_voodoo.rb +10 -17
- data/lib/image_voodoo/version.rb +1 -1
- data/test/test_image_science.rb +11 -2
- metadata +2 -2
data/bin/image_voodoo
CHANGED
@@ -40,7 +40,7 @@ opts = OptionParser.new do |opts|
|
|
40
40
|
actions << lambda {|img| img.adjust_brightness(scale, offset) }
|
41
41
|
end
|
42
42
|
|
43
|
-
opts.on("-B" "--border WIDTH,COLOR,STYLE", "Add a simple border") do |args|
|
43
|
+
opts.on("-B", "--border WIDTH,COLOR,STYLE", "Add a simple border") do |args|
|
44
44
|
width, color, style = args.split(/\,/i)
|
45
45
|
options = {:width => width, :color => color, :style => style }
|
46
46
|
|
data/lib/image_voodoo.rb
CHANGED
@@ -123,12 +123,8 @@ class ImageVoodoo
|
|
123
123
|
l, r = half, half + height if width > height
|
124
124
|
t, b = half, half + width if height > width
|
125
125
|
|
126
|
-
with_crop(l, t, r, b)
|
127
|
-
|
128
|
-
target = ImageVoodoo.new target
|
129
|
-
block_given? ? yield(target) : target
|
130
|
-
end
|
131
|
-
end
|
126
|
+
target = with_crop(l, t, r, b).thumbnail(size)
|
127
|
+
block_given? ? yield(target) : target
|
132
128
|
end
|
133
129
|
|
134
130
|
#
|
@@ -212,10 +208,8 @@ class ImageVoodoo
|
|
212
208
|
def scale(ratio)
|
213
209
|
new_width, new_height = (width * ratio).to_i, (height * ratio).to_i
|
214
210
|
|
215
|
-
resize(new_width, new_height)
|
216
|
-
|
217
|
-
block_given? ? yield(target) : target
|
218
|
-
end
|
211
|
+
target = resize(new_width, new_height)
|
212
|
+
block_given? ? yield(target) : target
|
219
213
|
end
|
220
214
|
|
221
215
|
#
|
@@ -223,7 +217,8 @@ class ImageVoodoo
|
|
223
217
|
# edge is resized to size and yields/returns the new image.
|
224
218
|
#
|
225
219
|
def thumbnail(size)
|
226
|
-
scale(size.to_f / (width > height ? width : height))
|
220
|
+
target = scale(size.to_f / (width > height ? width : height))
|
221
|
+
block_given? ? yield(target) : target
|
227
222
|
end
|
228
223
|
|
229
224
|
#
|
@@ -303,12 +298,10 @@ class ImageVoodoo
|
|
303
298
|
# A top-level image loader opens path and then yields/returns the image.
|
304
299
|
#
|
305
300
|
def self.with_image(file)
|
306
|
-
|
307
|
-
|
308
|
-
image = ImageVoodoo.new
|
309
|
-
block_given? ? yield(image) : image
|
310
|
-
rescue NativeException => ne
|
311
|
-
nil
|
301
|
+
raise ArgumentError, "file does not exist" unless File.file?(file)
|
302
|
+
buffered_image = ImageIO.read(JFile.new(file))
|
303
|
+
image = ImageVoodoo.new(buffered_image) if buffered_image
|
304
|
+
image && block_given? ? yield(image) : image
|
312
305
|
end
|
313
306
|
|
314
307
|
#
|
data/lib/image_voodoo/version.rb
CHANGED
data/test/test_image_science.rb
CHANGED
@@ -33,7 +33,7 @@ class TestImageScience < Test::Unit::TestCase
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def test_class_with_image_missing
|
36
|
-
assert_raises
|
36
|
+
assert_raises ArgumentError do
|
37
37
|
ImageScience.with_image @path + "nope" do |img|
|
38
38
|
flunk
|
39
39
|
end
|
@@ -41,7 +41,16 @@ class TestImageScience < Test::Unit::TestCase
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def test_class_with_image_missing_with_img_extension
|
44
|
-
|
44
|
+
assert_raises ArgumentError do
|
45
|
+
ImageScience.with_image("nope#{@path}") do |img|
|
46
|
+
flunk
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_class_with_image_return_nil_on_bogus_image
|
52
|
+
File.open(@tmppath, "w") {|f| f << "bogus image file"}
|
53
|
+
assert_nil ImageScience.with_image(@tmppath) do |img|
|
45
54
|
flunk
|
46
55
|
end
|
47
56
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: image_voodoo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "0.
|
4
|
+
version: "0.4"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Enebo, Charles Nutter and JRuby contributors
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-07-28 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|