quick_magick_hooopo 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +15 -0
- data/README.rdoc +195 -0
- data/Rakefile +15 -0
- data/lib/quick_magick.rb +208 -0
- data/lib/quick_magick/image.rb +495 -0
- data/lib/quick_magick/image_list.rb +60 -0
- data/quick_magick_hooopo.gemspec +30 -0
- data/test/9.gif +0 -0
- data/test/badfile.xxx +0 -0
- data/test/image_list_test.rb +114 -0
- data/test/image_test.rb +336 -0
- data/test/multipage.tif +0 -0
- data/test/test_magick.rb +169 -0
- data/test/test_quick_magick.rb +17 -0
- data/test/warnings.tiff +0 -0
- metadata +75 -0
@@ -0,0 +1,60 @@
|
|
1
|
+
module QuickMagick
|
2
|
+
class ImageList
|
3
|
+
|
4
|
+
def initialize(*filenames)
|
5
|
+
@images = filenames.inject([]) do |image_list, filename|
|
6
|
+
image_list + QuickMagick::Image.read(filename)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
# Delegate Array methods
|
11
|
+
Array.public_instance_methods(false).each do |array_public_method|
|
12
|
+
class_eval do
|
13
|
+
define_method array_public_method do |*args|
|
14
|
+
@images.send array_public_method, *args
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Delegate Image methods
|
20
|
+
QuickMagick::Image.public_instance_methods(false).each do |image_public_method|
|
21
|
+
class_eval do
|
22
|
+
define_method image_public_method do |*args|
|
23
|
+
@images.each do |image|
|
24
|
+
image.send image_public_method, *args
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Saves all images in the list to the output filename
|
31
|
+
def save(output_filename)
|
32
|
+
command_line = ""
|
33
|
+
@images.each do |image|
|
34
|
+
command_line << image.command_line
|
35
|
+
end
|
36
|
+
`convert #{command_line} "#{output_filename}"`
|
37
|
+
end
|
38
|
+
|
39
|
+
alias write save
|
40
|
+
|
41
|
+
# Returns an array of images for the images stored
|
42
|
+
def to_ary
|
43
|
+
@images
|
44
|
+
end
|
45
|
+
|
46
|
+
alias to_a to_ary
|
47
|
+
|
48
|
+
def <<(more_images)
|
49
|
+
case more_images
|
50
|
+
when QuickMagick::Image then @images << more_images
|
51
|
+
# Another image list
|
52
|
+
when QuickMagick::ImageList then self << more_images.to_a
|
53
|
+
when Array then @images += more_images
|
54
|
+
else raise QuickMagick::QuickMagickError, "Invalid argument type"
|
55
|
+
end
|
56
|
+
self
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "quick_magick_hooopo"
|
5
|
+
s.version = "0.8.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Ahmed ElDawy"]
|
9
|
+
s.date = "2012-02-18"
|
10
|
+
s.description = "QuickMagick allows you to access ImageMagick command line functions using Ruby interface."
|
11
|
+
s.email = "ahmed.eldawy@badrit.com"
|
12
|
+
s.extra_rdoc_files = ["README.rdoc", "lib/quick_magick.rb", "lib/quick_magick/image.rb", "lib/quick_magick/image_list.rb"]
|
13
|
+
s.files = ["Manifest", "README.rdoc", "Rakefile", "lib/quick_magick.rb", "lib/quick_magick/image.rb", "lib/quick_magick/image_list.rb", "quick_magick_hooopo.gemspec", "test/9.gif", "test/badfile.xxx", "test/image_list_test.rb", "test/image_test.rb", "test/multipage.tif", "test/test_magick.rb", "test/test_quick_magick.rb", "test/warnings.tiff"]
|
14
|
+
s.homepage = "http://quickmagick.rubyforge.org/"
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Quick_magick_hooopo", "--main", "README.rdoc"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = "quickmagick"
|
18
|
+
s.rubygems_version = "1.8.11"
|
19
|
+
s.summary = "A gem build by BadrIT to access ImageMagick command line functions easily and quickly"
|
20
|
+
s.test_files = ["test/test_quick_magick.rb", "test/image_test.rb", "test/image_list_test.rb", "test/test_magick.rb"]
|
21
|
+
|
22
|
+
if s.respond_to? :specification_version then
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
+
else
|
27
|
+
end
|
28
|
+
else
|
29
|
+
end
|
30
|
+
end
|
data/test/9.gif
ADDED
Binary file
|
data/test/badfile.xxx
ADDED
Binary file
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'quick_magick'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
$base_dir = File.dirname(File.expand_path(__FILE__))
|
6
|
+
|
7
|
+
class ImageTest < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
@logo_filename = File.join($base_dir, "imagemagick-logo.png")
|
10
|
+
`convert magick:logo "#{@logo_filename}"`
|
11
|
+
@small_logo_filename = File.join($base_dir, "logo-small.jpg")
|
12
|
+
`convert magick:logo -resize 100x100! "#{@small_logo_filename}"`
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown
|
16
|
+
File.delete(@logo_filename) if File.exists?(@logo_filename)
|
17
|
+
File.delete(@small_logo_filename) if File.exists?(@small_logo_filename)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_open_file
|
21
|
+
i = QuickMagick::ImageList.new(@logo_filename)
|
22
|
+
assert_equal 1, i.length
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_save_multipage
|
26
|
+
i = QuickMagick::ImageList.new(@logo_filename, @small_logo_filename)
|
27
|
+
assert_equal 2, i.length
|
28
|
+
out_filename = File.join($base_dir, "out.tif")
|
29
|
+
i.save out_filename
|
30
|
+
|
31
|
+
i = QuickMagick::Image.read(out_filename)
|
32
|
+
assert_equal 2, i.length
|
33
|
+
assert_equal 100, i[1].width
|
34
|
+
ensure
|
35
|
+
File.delete(out_filename) if out_filename && File.exists?(out_filename)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_bulk_resize
|
39
|
+
i = QuickMagick::ImageList.new(@logo_filename, @small_logo_filename)
|
40
|
+
i.resize "50x50!"
|
41
|
+
out_filename = File.join($base_dir, "out.tif")
|
42
|
+
i.save out_filename
|
43
|
+
|
44
|
+
i = QuickMagick::Image.read(out_filename)
|
45
|
+
assert_equal 2, i.length
|
46
|
+
assert_equal 50, i[0].width
|
47
|
+
assert_equal 50, i[1].width
|
48
|
+
ensure
|
49
|
+
File.delete(out_filename) if out_filename && File.exists?(out_filename)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_append_image
|
53
|
+
i = QuickMagick::ImageList.new
|
54
|
+
i << QuickMagick::Image.read(@logo_filename)
|
55
|
+
i << QuickMagick::Image.read(@small_logo_filename)
|
56
|
+
i.resize "50x50!"
|
57
|
+
out_filename = File.join($base_dir, "out.tif")
|
58
|
+
i.save out_filename
|
59
|
+
|
60
|
+
i = QuickMagick::Image.read(out_filename)
|
61
|
+
assert_equal 2, i.length
|
62
|
+
assert_equal 50, i[0].width
|
63
|
+
assert_equal 50, i[1].width
|
64
|
+
ensure
|
65
|
+
File.delete(out_filename) if out_filename && File.exists?(out_filename)
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_different_operators
|
69
|
+
i = QuickMagick::ImageList.new
|
70
|
+
i << QuickMagick::Image.read(@logo_filename)
|
71
|
+
i << QuickMagick::Image.read(@small_logo_filename)
|
72
|
+
i[0].resize "50x50!"
|
73
|
+
i[1].resize "75x75!"
|
74
|
+
out_filename = File.join($base_dir, "out.tif")
|
75
|
+
i.save out_filename
|
76
|
+
|
77
|
+
i = QuickMagick::Image.read(out_filename)
|
78
|
+
assert_equal 2, i.length
|
79
|
+
assert_equal 50, i[0].width
|
80
|
+
assert_equal 75, i[1].width
|
81
|
+
ensure
|
82
|
+
File.delete(out_filename) if out_filename && File.exists?(out_filename)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_resize_one_image_in_a_list
|
86
|
+
i = QuickMagick::ImageList.new
|
87
|
+
i << QuickMagick::Image.read(@logo_filename)
|
88
|
+
i << QuickMagick::Image.read(@small_logo_filename)
|
89
|
+
i[0].resize "50x50!"
|
90
|
+
out_filename = File.join($base_dir, "out.tif")
|
91
|
+
i.save out_filename
|
92
|
+
|
93
|
+
i = QuickMagick::Image.read(out_filename)
|
94
|
+
assert_equal 2, i.length
|
95
|
+
assert_equal 50, i[0].width
|
96
|
+
assert_equal 100, i[1].width
|
97
|
+
ensure
|
98
|
+
File.delete(out_filename) if out_filename && File.exists?(out_filename)
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_bulk_convert
|
102
|
+
i = QuickMagick::ImageList.new(@logo_filename, @small_logo_filename)
|
103
|
+
i.format = 'gif'
|
104
|
+
i.save!
|
105
|
+
|
106
|
+
out_filename1 = @logo_filename.sub('.png', '.gif')
|
107
|
+
out_filename2 = @small_logo_filename.sub('.jpg', '.gif')
|
108
|
+
assert File.exists?(out_filename1)
|
109
|
+
assert File.exists?(out_filename2)
|
110
|
+
ensure
|
111
|
+
File.delete(out_filename1) if out_filename1 && File.exists?(out_filename1)
|
112
|
+
File.delete(out_filename2) if out_filename2 && File.exists?(out_filename2)
|
113
|
+
end
|
114
|
+
end
|
data/test/image_test.rb
ADDED
@@ -0,0 +1,336 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'quick_magick'
|
3
|
+
|
4
|
+
$base_dir = File.dirname(File.expand_path(__FILE__))
|
5
|
+
|
6
|
+
class ImageTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@logo_filename = File.join($base_dir, "imagemagick-logo.png")
|
10
|
+
`convert magick:logo "#{@logo_filename}"`
|
11
|
+
@small_logo_filename = File.join($base_dir, "logo-small.jpg")
|
12
|
+
`convert magick:logo -resize 100x100! "#{@small_logo_filename}"`
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown
|
16
|
+
File.delete(@logo_filename) if File.exists?(@logo_filename)
|
17
|
+
File.delete(@small_logo_filename) if File.exists?(@small_logo_filename)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_open_existing_image
|
21
|
+
i = QuickMagick::Image.read(@logo_filename)
|
22
|
+
assert_equal 1, i.size
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_skip_warnings
|
26
|
+
filename = File.join($base_dir, "warnings.tiff")
|
27
|
+
i = QuickMagick::Image.read(filename)
|
28
|
+
assert_equal 1, i.size
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_create_from_blob
|
32
|
+
blob = nil
|
33
|
+
File.open(@logo_filename, "rb") do |f|
|
34
|
+
blob = f.read
|
35
|
+
end
|
36
|
+
i = QuickMagick::Image.from_blob(blob)
|
37
|
+
assert_equal 1, i.size
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_multipage_with_blob
|
41
|
+
blob = nil
|
42
|
+
image_filename = File.join($base_dir, "multipage.tif")
|
43
|
+
File.open(image_filename, "rb") do |f|
|
44
|
+
blob = f.read
|
45
|
+
end
|
46
|
+
i = QuickMagick::Image.from_blob(blob)
|
47
|
+
assert_equal 2, i.size
|
48
|
+
|
49
|
+
out1 = File.join($base_dir, "test1.jpg")
|
50
|
+
out2 = File.join($base_dir, "test2.jpg")
|
51
|
+
i.pop.save out1
|
52
|
+
i.pop.save out2
|
53
|
+
assert_equal 464, QuickMagick::Image.read(out1).first.width
|
54
|
+
assert_equal 100, QuickMagick::Image.read(out2).first.width
|
55
|
+
ensure
|
56
|
+
File.delete(out1) if out1 && File.exists?(out1)
|
57
|
+
File.delete(out2) if out2 && File.exists?(out2)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_image_info
|
61
|
+
i = QuickMagick::Image.read(@logo_filename).first
|
62
|
+
assert_equal 640, i.width
|
63
|
+
assert_equal 480, i.height
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_open_non_existing_file
|
67
|
+
image_filename = File.join($base_dir, "space.png")
|
68
|
+
assert_raises QuickMagick::QuickMagickError do
|
69
|
+
i = QuickMagick::Image.read(image_filename)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_open_bad_file
|
74
|
+
image_filename = File.join($base_dir, "badfile.xxx")
|
75
|
+
assert_raises QuickMagick::QuickMagickError do
|
76
|
+
i = QuickMagick::Image.read(image_filename)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_open_mulitpage_file
|
81
|
+
image_filename = File.join($base_dir, "multipage.tif")
|
82
|
+
i = QuickMagick::Image.read(image_filename)
|
83
|
+
assert_equal 2, i.size
|
84
|
+
assert_equal 100, i[0].width
|
85
|
+
assert_equal 464, i[1].width
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_resize_image
|
89
|
+
i = QuickMagick::Image.read(@logo_filename).first
|
90
|
+
i.resize("300x300!")
|
91
|
+
out_filename = File.join($base_dir, "imagemagick-resized.png")
|
92
|
+
File.delete out_filename if File.exists?(out_filename)
|
93
|
+
i.save(out_filename)
|
94
|
+
assert File.exists?(out_filename)
|
95
|
+
i2 = QuickMagick::Image.read(out_filename).first
|
96
|
+
assert_equal 300, i2.width
|
97
|
+
assert_equal 300, i2.height
|
98
|
+
ensure
|
99
|
+
# clean up
|
100
|
+
File.delete(out_filename) if out_filename && File.exists?(out_filename)
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
def test_monochrome
|
105
|
+
i = QuickMagick::Image.read(@logo_filename).first
|
106
|
+
i.resize("300x300!")
|
107
|
+
i.monochrome
|
108
|
+
out_filename = File.join($base_dir, "imagemagick-resized.png")
|
109
|
+
File.delete out_filename if File.exists?(out_filename)
|
110
|
+
i.save(out_filename)
|
111
|
+
assert File.exists?(out_filename)
|
112
|
+
i2 = QuickMagick::Image.read(out_filename).first
|
113
|
+
assert_equal 300, i2.width
|
114
|
+
assert_equal 300, i2.height
|
115
|
+
ensure
|
116
|
+
# clean up
|
117
|
+
File.delete(out_filename) if out_filename && File.exists?(out_filename)
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_read_with_initialize
|
121
|
+
i = QuickMagick::Image.read(@logo_filename) do |image|
|
122
|
+
image.resize("300x300!")
|
123
|
+
image.colors = 2
|
124
|
+
end.first
|
125
|
+
out_filename = File.join($base_dir, "imagemagick-resized.png")
|
126
|
+
File.delete out_filename if File.exists?(out_filename)
|
127
|
+
i.save(out_filename)
|
128
|
+
assert File.exists?(out_filename)
|
129
|
+
i2 = QuickMagick::Image.read(out_filename).first
|
130
|
+
assert_equal 300, i2.width
|
131
|
+
assert_equal 300, i2.height
|
132
|
+
ensure
|
133
|
+
# clean up
|
134
|
+
File.delete(out_filename) if out_filename && File.exists?(out_filename)
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_crop_image
|
138
|
+
i = QuickMagick::Image.read(@logo_filename).first
|
139
|
+
i.crop("300x200+0+0")
|
140
|
+
out_filename = File.join($base_dir, "imagemagick-cropped.png")
|
141
|
+
File.delete out_filename if File.exists?(out_filename)
|
142
|
+
i.save(out_filename)
|
143
|
+
assert File.exists?(out_filename)
|
144
|
+
i2 = QuickMagick::Image.read(out_filename).first
|
145
|
+
assert_equal 300, i2.width
|
146
|
+
assert_equal 200, i2.height
|
147
|
+
ensure
|
148
|
+
# clean up
|
149
|
+
File.delete(out_filename) if out_filename && File.exists?(out_filename)
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_resize_with_geometry_options
|
153
|
+
i = QuickMagick::Image.read(@logo_filename).first
|
154
|
+
i.resize(300, 300, nil, nil, QuickMagick::AspectGeometry)
|
155
|
+
out_filename = File.join($base_dir, "imagemagick-resized.png")
|
156
|
+
File.delete out_filename if File.exists?(out_filename)
|
157
|
+
i.save(out_filename)
|
158
|
+
assert File.exists?(out_filename)
|
159
|
+
i2 = QuickMagick::Image.read(out_filename).first
|
160
|
+
assert_equal 300, i2.width
|
161
|
+
assert_equal 300, i2.height
|
162
|
+
ensure
|
163
|
+
# clean up
|
164
|
+
File.delete(out_filename) if out_filename && File.exists?(out_filename)
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_resize_with_append_to_operators
|
168
|
+
i = QuickMagick::Image.read(@logo_filename).first
|
169
|
+
i.append_to_operators 'resize', '300x300!'
|
170
|
+
out_filename = File.join($base_dir, "imagemagick-resized.png")
|
171
|
+
File.delete out_filename if File.exists?(out_filename)
|
172
|
+
i.save(out_filename)
|
173
|
+
assert File.exists?(out_filename)
|
174
|
+
i2 = QuickMagick::Image.read(out_filename).first
|
175
|
+
assert_equal 300, i2.width
|
176
|
+
assert_equal 300, i2.height
|
177
|
+
ensure
|
178
|
+
# clean up
|
179
|
+
File.delete(out_filename) if out_filename && File.exists?(out_filename)
|
180
|
+
end
|
181
|
+
|
182
|
+
def test_create_solid_image
|
183
|
+
i = QuickMagick::Image.solid(100, 100, :white)
|
184
|
+
#assert_equal 100, i.width
|
185
|
+
end
|
186
|
+
|
187
|
+
def test_create_gradient_image
|
188
|
+
i = QuickMagick::Image.gradient(100, 100, QuickMagick::RadialGradient, :yellow, :blue)
|
189
|
+
#assert_equal 100, i.width
|
190
|
+
end
|
191
|
+
|
192
|
+
def test_line_primitive
|
193
|
+
i = QuickMagick::Image.solid(100, 100, :white)
|
194
|
+
i.draw_line(0, 0, 50, 50)
|
195
|
+
out_filename = File.join($base_dir, "line_test.gif")
|
196
|
+
i.save out_filename
|
197
|
+
ensure
|
198
|
+
# clean up
|
199
|
+
File.delete(out_filename) if out_filename && File.exists?(out_filename)
|
200
|
+
end
|
201
|
+
|
202
|
+
def test_text_primitive
|
203
|
+
i = QuickMagick::Image.solid(100, 100, :white)
|
204
|
+
i.draw_text(0, 50, "Ahmed Eldawy")
|
205
|
+
out_filename = File.join($base_dir, "text_test.gif")
|
206
|
+
i.save out_filename
|
207
|
+
ensure
|
208
|
+
# clean up
|
209
|
+
File.delete(out_filename) if out_filename && File.exists?(out_filename)
|
210
|
+
end
|
211
|
+
|
212
|
+
def test_line_and_circle
|
213
|
+
i = QuickMagick::Image.solid(100, 100)
|
214
|
+
i.draw_line(0,0,20,20)
|
215
|
+
i.draw_circle(30,30,20,20)
|
216
|
+
assert_equal %Q{ "(" -size 100x100 -draw " line 0,0 20,20 circle 30,30 20,20" "xc:" ")" }, i.command_line
|
217
|
+
out_filename = File.join($base_dir, "draw_test.gif")
|
218
|
+
i.save out_filename
|
219
|
+
ensure
|
220
|
+
# clean up
|
221
|
+
File.delete(out_filename) if out_filename && File.exists?(out_filename)
|
222
|
+
end
|
223
|
+
|
224
|
+
def test_lines_with_colors
|
225
|
+
i = QuickMagick::Image.solid(100, 100, :white)
|
226
|
+
i.stroke = "red"
|
227
|
+
i.draw_line(0,0,20,20)
|
228
|
+
i.stroke = "blue"
|
229
|
+
i.draw_circle(30,30,20,20)
|
230
|
+
out_filename = File.join($base_dir, "draw_test.gif")
|
231
|
+
i.save out_filename
|
232
|
+
ensure
|
233
|
+
# clean up
|
234
|
+
File.delete(out_filename) if out_filename && File.exists?(out_filename)
|
235
|
+
end
|
236
|
+
|
237
|
+
def test_to_blob_default_format
|
238
|
+
i = QuickMagick::Image.solid(100, 100)
|
239
|
+
i.draw_line(0,0,20,20)
|
240
|
+
i.draw_circle(30,30,20,20)
|
241
|
+
blob = i.to_blob
|
242
|
+
i2 = QuickMagick::Image.from_blob(blob).first
|
243
|
+
assert_equal 100, i2.width
|
244
|
+
assert_equal 100, i2.height
|
245
|
+
assert_equal 'JPEG', i2.format
|
246
|
+
end
|
247
|
+
|
248
|
+
def test_to_blob_with_custom_format
|
249
|
+
i = QuickMagick::Image.solid(100, 100)
|
250
|
+
i.draw_line(0,0,20,20)
|
251
|
+
i.draw_circle(30,30,20,20)
|
252
|
+
i.format = 'gif'
|
253
|
+
blob = i.to_blob
|
254
|
+
i2 = QuickMagick::Image.from_blob(blob).first
|
255
|
+
assert_equal 'GIF', i2.format
|
256
|
+
end
|
257
|
+
|
258
|
+
def test_to_blob_with_original_format
|
259
|
+
i = QuickMagick::Image.read(@logo_filename).first
|
260
|
+
blob = i.to_blob
|
261
|
+
i2 = QuickMagick::Image.from_blob(blob).first
|
262
|
+
assert_equal 'PNG', i2.format
|
263
|
+
end
|
264
|
+
|
265
|
+
def test_colors
|
266
|
+
assert_equal "#00ff00ff", QuickMagick::rgb_color(0, 255, 0)
|
267
|
+
assert_equal "#00007fff", QuickMagick::rgb_color(0, 0, 0.5)
|
268
|
+
assert_equal "#3f0000ff", QuickMagick::rgb_color("25%" ,0 , 0)
|
269
|
+
|
270
|
+
assert_equal "#ff00007f", QuickMagick::rgba_color(1.0, 0, 0, 0.5)
|
271
|
+
|
272
|
+
assert_equal "#7f7f7f7f", QuickMagick::graya_color(0.5, 0.5)
|
273
|
+
|
274
|
+
assert_equal "hsla(30,50%,50%,1)", QuickMagick::hsl_color(30, 127, 127)
|
275
|
+
assert_equal "hsla(180,50%,50%,0.5)", QuickMagick::hsla_color(Math::PI, 0.5, "50%", 0.5)
|
276
|
+
end
|
277
|
+
|
278
|
+
def test_revert
|
279
|
+
i = QuickMagick::Image.read(@logo_filename).first
|
280
|
+
i.resize("300x300!")
|
281
|
+
i.revert!
|
282
|
+
out_filename = File.join($base_dir, "imagemagick-resized.png")
|
283
|
+
File.delete out_filename if File.exists?(out_filename)
|
284
|
+
i.save(out_filename)
|
285
|
+
assert File.exists?(out_filename)
|
286
|
+
i2 = QuickMagick::Image.read(out_filename).first
|
287
|
+
assert_equal 640, i2.width
|
288
|
+
assert_equal 480, i2.height
|
289
|
+
ensure
|
290
|
+
File.delete out_filename if File.exists?(out_filename)
|
291
|
+
end
|
292
|
+
|
293
|
+
def test_image_converted_from_pseudo_to_normal
|
294
|
+
i = QuickMagick::Image.solid(100, 100, :white)
|
295
|
+
i.stroke = "red"
|
296
|
+
i.draw_line(0,0,20,20)
|
297
|
+
out_filename = File.join($base_dir, "draw_test.gif")
|
298
|
+
assert_raises QuickMagick::QuickMagickError do
|
299
|
+
i.save!
|
300
|
+
end
|
301
|
+
i.save out_filename
|
302
|
+
# Now it's non pseudo
|
303
|
+
i.save!
|
304
|
+
end
|
305
|
+
|
306
|
+
def test_antialias
|
307
|
+
i = QuickMagick::Image.solid(100, 100, :white)
|
308
|
+
i.antialias = false
|
309
|
+
assert i.command_line =~ /\+antialias/
|
310
|
+
|
311
|
+
i = QuickMagick::Image.solid(100, 100, :white)
|
312
|
+
i.antialias = true
|
313
|
+
assert i.command_line =~ /\-antialias/
|
314
|
+
|
315
|
+
i = QuickMagick::Image.solid(100, 100, :white) { |img| img.antialias = false}
|
316
|
+
assert i.command_line =~ /\+antialias/
|
317
|
+
end
|
318
|
+
|
319
|
+
def test_get_pixel
|
320
|
+
image = QuickMagick::Image.read(@logo_filename)[0]
|
321
|
+
assert_equal [2,90,164], image.get_pixel(356, 286)
|
322
|
+
end
|
323
|
+
|
324
|
+
def test_get_pixel_with_multipage
|
325
|
+
image_filename = File.join($base_dir, "multipage.tif")
|
326
|
+
image = QuickMagick::Image.read(image_filename)[1]
|
327
|
+
assert_equal [234,43,44], image.get_pixel(256,73)
|
328
|
+
end
|
329
|
+
|
330
|
+
def test_details
|
331
|
+
image_details = QuickMagick::Image.read(@logo_filename)[0].details
|
332
|
+
assert_equal Hash, image_details.class
|
333
|
+
assert_equal ["Image"], image_details.keys
|
334
|
+
assert_equal "228.364 (0.895545)", image_details["Image"]["Channel statistics"]["Red"]["mean"]
|
335
|
+
end
|
336
|
+
end
|