mini_magick 1.2.3 → 2.0.0
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/MIT-LICENSE +0 -0
- data/README.rdoc +81 -0
- data/Rakefile +28 -13
- data/VERSION +1 -0
- data/lib/mini_gmagick.rb +2 -0
- data/lib/mini_magick.rb +171 -41
- data/test/actually_a_gif.jpg +0 -0
- data/test/animation.gif +0 -0
- data/test/command_builder_test.rb +45 -0
- data/test/composited.jpg +0 -0
- data/test/image_test.rb +205 -0
- data/test/leaves.tiff +0 -0
- data/test/not_an_image.php +1 -604
- data/test/simple-minus.gif +0 -0
- data/test/simple.gif +0 -0
- data/test/trogdor.jpg +0 -0
- metadata +89 -53
- data/History.txt +0 -11
- data/Manifest.txt +0 -14
- data/README.txt +0 -101
- data/init.rb +0 -2
- data/lib/image_temp_file.rb +0 -13
- data/test/test_image_temp_file.rb +0 -14
- data/test/test_mini_magick_test.rb +0 -127
data/test/image_test.rb
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'test/unit'
|
|
3
|
+
require File.expand_path('../../lib/mini_magick', __FILE__)
|
|
4
|
+
|
|
5
|
+
#MiniMagick.processor = :gm
|
|
6
|
+
|
|
7
|
+
class ImageTest < Test::Unit::TestCase
|
|
8
|
+
include MiniMagick
|
|
9
|
+
|
|
10
|
+
CURRENT_DIR = File.dirname(File.expand_path(__FILE__)) + "/"
|
|
11
|
+
|
|
12
|
+
SIMPLE_IMAGE_PATH = CURRENT_DIR + "simple.gif"
|
|
13
|
+
MINUS_IMAGE_PATH = CURRENT_DIR + "simple-minus.gif"
|
|
14
|
+
TIFF_IMAGE_PATH = CURRENT_DIR + "leaves.tiff"
|
|
15
|
+
NOT_AN_IMAGE_PATH = CURRENT_DIR + "not_an_image.php"
|
|
16
|
+
GIF_WITH_JPG_EXT = CURRENT_DIR + "actually_a_gif.jpg"
|
|
17
|
+
EXIF_IMAGE_PATH = CURRENT_DIR + "trogdor.jpg"
|
|
18
|
+
ANIMATION_PATH = CURRENT_DIR + "animation.gif"
|
|
19
|
+
|
|
20
|
+
def test_image_from_blob
|
|
21
|
+
File.open(SIMPLE_IMAGE_PATH, "rb") do |f|
|
|
22
|
+
image = Image.from_blob(f.read)
|
|
23
|
+
image.destroy!
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_image_from_file
|
|
28
|
+
image = Image.from_file(SIMPLE_IMAGE_PATH)
|
|
29
|
+
image.destroy!
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def test_image_new
|
|
33
|
+
image = Image.new(SIMPLE_IMAGE_PATH)
|
|
34
|
+
image.destroy!
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_image_write
|
|
38
|
+
output_path = "output.gif"
|
|
39
|
+
begin
|
|
40
|
+
image = Image.new(SIMPLE_IMAGE_PATH)
|
|
41
|
+
image.write output_path
|
|
42
|
+
|
|
43
|
+
assert File.exists?(output_path)
|
|
44
|
+
ensure
|
|
45
|
+
File.delete output_path
|
|
46
|
+
end
|
|
47
|
+
image.destroy!
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def test_not_an_image
|
|
51
|
+
image = Image.new(NOT_AN_IMAGE_PATH)
|
|
52
|
+
assert_equal false, image.valid?
|
|
53
|
+
image.destroy!
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def test_throw_on_openining_not_an_image
|
|
57
|
+
assert_raise(MiniMagick::Invalid) do
|
|
58
|
+
image = Image.open(NOT_AN_IMAGE_PATH)
|
|
59
|
+
image.destroy
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def test_image_meta_info
|
|
64
|
+
image = Image.new(SIMPLE_IMAGE_PATH)
|
|
65
|
+
assert_equal 150, image[:width]
|
|
66
|
+
assert_equal 55, image[:height]
|
|
67
|
+
assert_equal [150, 55], image[:dimensions]
|
|
68
|
+
assert_match(/^gif$/i, image[:format])
|
|
69
|
+
image.destroy!
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def test_tiff
|
|
73
|
+
image = Image.new(TIFF_IMAGE_PATH)
|
|
74
|
+
assert_equal "tiff", image[:format].downcase
|
|
75
|
+
assert_equal 50, image[:width]
|
|
76
|
+
assert_equal 41, image[:height]
|
|
77
|
+
image.destroy!
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# def test_animation_pages
|
|
81
|
+
# image = Image.from_file(ANIMATION_PATH)
|
|
82
|
+
# image.format "png", 0
|
|
83
|
+
# assert_equal "png", image[:format].downcase
|
|
84
|
+
# image.destroy!
|
|
85
|
+
# end
|
|
86
|
+
|
|
87
|
+
# def test_animation_size
|
|
88
|
+
# image = Image.from_file(ANIMATION_PATH)
|
|
89
|
+
# assert_equal image[:size], 76631
|
|
90
|
+
# image.destroy!
|
|
91
|
+
# end
|
|
92
|
+
|
|
93
|
+
def test_gif_with_jpg_format
|
|
94
|
+
image = Image.new(GIF_WITH_JPG_EXT)
|
|
95
|
+
assert_equal "gif", image[:format].downcase
|
|
96
|
+
image.destroy!
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def test_image_resize
|
|
100
|
+
image = Image.from_file(SIMPLE_IMAGE_PATH)
|
|
101
|
+
image.resize "20x30!"
|
|
102
|
+
|
|
103
|
+
assert_equal 20, image[:width]
|
|
104
|
+
assert_equal 30, image[:height]
|
|
105
|
+
assert_match(/^gif$/i, image[:format])
|
|
106
|
+
image.destroy!
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def test_image_resize_with_minimum
|
|
110
|
+
image = Image.from_file(SIMPLE_IMAGE_PATH)
|
|
111
|
+
original_width, original_height = image[:width], image[:height]
|
|
112
|
+
image.resize "#{original_width + 10}x#{original_height + 10}>"
|
|
113
|
+
|
|
114
|
+
assert_equal original_width, image[:width]
|
|
115
|
+
assert_equal original_height, image[:height]
|
|
116
|
+
image.destroy!
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def test_image_combine_options_resize_blur
|
|
120
|
+
image = Image.from_file(SIMPLE_IMAGE_PATH)
|
|
121
|
+
image.combine_options do |c|
|
|
122
|
+
c.resize "20x30!"
|
|
123
|
+
c.blur 50
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
assert_equal 20, image[:width]
|
|
127
|
+
assert_equal 30, image[:height]
|
|
128
|
+
assert_match(/^gif$/i, image[:format])
|
|
129
|
+
image.destroy!
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def test_image_combine_options_with_filename_with_minusses_in_it
|
|
133
|
+
image = Image.from_file(SIMPLE_IMAGE_PATH)
|
|
134
|
+
assert_nothing_raised do
|
|
135
|
+
image.combine_options do |c|
|
|
136
|
+
c.draw "image Over 0,0 10,10 '#{MINUS_IMAGE_PATH}'"
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
image.destroy!
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def test_exif
|
|
143
|
+
image = Image.from_file(EXIF_IMAGE_PATH)
|
|
144
|
+
assert_equal('0220', image["exif:ExifVersion"])
|
|
145
|
+
image = Image.from_file(SIMPLE_IMAGE_PATH)
|
|
146
|
+
assert_equal('', image["EXIF:ExifVersion"])
|
|
147
|
+
image.destroy!
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def test_original_at
|
|
151
|
+
image = Image.from_file(EXIF_IMAGE_PATH)
|
|
152
|
+
assert_equal(Time.local('2005', '2', '23', '23', '17', '24'), image[:original_at])
|
|
153
|
+
image = Image.from_file(SIMPLE_IMAGE_PATH)
|
|
154
|
+
assert_nil(image[:original_at])
|
|
155
|
+
image.destroy!
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def test_tempfile_at_path
|
|
159
|
+
image = Image.from_file(TIFF_IMAGE_PATH)
|
|
160
|
+
assert_equal image.path, image.tempfile.path
|
|
161
|
+
image.destroy!
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def test_tempfile_at_path_after_format
|
|
165
|
+
image = Image.from_file(TIFF_IMAGE_PATH)
|
|
166
|
+
image.format('png')
|
|
167
|
+
assert_equal image.path, image.tempfile.path
|
|
168
|
+
image.destroy!
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
def test_previous_tempfile_deleted_after_format
|
|
172
|
+
image = Image.from_file(TIFF_IMAGE_PATH)
|
|
173
|
+
before = image.path.dup
|
|
174
|
+
image.format('png')
|
|
175
|
+
assert !File.exist?(before)
|
|
176
|
+
image.destroy!
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def test_bad_method_bug
|
|
180
|
+
image = Image.from_file(TIFF_IMAGE_PATH)
|
|
181
|
+
begin
|
|
182
|
+
image.to_blog
|
|
183
|
+
rescue NoMethodError
|
|
184
|
+
assert true
|
|
185
|
+
end
|
|
186
|
+
image.to_blob
|
|
187
|
+
assert true #we made it this far without error
|
|
188
|
+
image.destroy!
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
def test_simple_composite
|
|
192
|
+
image = Image.from_file(EXIF_IMAGE_PATH)
|
|
193
|
+
result = image.composite(Image.open(TIFF_IMAGE_PATH)) do |c|
|
|
194
|
+
c.gravity "center"
|
|
195
|
+
end
|
|
196
|
+
assert `diff -s #{result.path} test/composited.jpg`.include?("identical")
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
# def test_mini_magick_error_when_referencing_not_existing_page
|
|
200
|
+
# image = Image.from_file(ANIMATION_PATH)
|
|
201
|
+
# image.format('png')
|
|
202
|
+
# assert_equal image[:format], 'PNG'
|
|
203
|
+
# image.destroy!
|
|
204
|
+
# end
|
|
205
|
+
end
|
data/test/leaves.tiff
ADDED
|
Binary file
|