aseldawy-quick_magick 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Binary file
@@ -0,0 +1,169 @@
1
+ if __FILE__ == $0
2
+ require 'rubygems'
3
+ require 'mini_magick'
4
+ require 'quick_magick'
5
+ require 'RMagick'
6
+ require 'benchmark'
7
+ require 'ftools'
8
+
9
+ begin
10
+ include Benchmark
11
+
12
+ $base_dir = File.dirname(File.expand_path(__FILE__))
13
+
14
+ # Generate a test file
15
+ in_file = File.join($base_dir, 'logo.png')
16
+ out_file = File.join($base_dir, 'testout.gif')
17
+
18
+ `convert magick:logo #{in_file}`
19
+
20
+ test_quick = lambda {
21
+ image_filename =
22
+ 20.times {
23
+ i = QuickMagick::Image.read(in_file).first
24
+ i.resize "100x100!"
25
+ i.save out_file
26
+ }
27
+ }
28
+
29
+ test_mini = lambda {
30
+ 20.times {
31
+ i = MiniMagick::Image.from_file(in_file)
32
+ i.combine_options do |c|
33
+ c.resize "100x100!"
34
+ c.format "gif"
35
+ end
36
+ i.write out_file
37
+ }
38
+ }
39
+
40
+ test_r = lambda {
41
+ 20.times {
42
+ i = Magick::Image.read(in_file).first
43
+ i = i.change_geometry!('100x100!') { |cols, rows, img|
44
+ img.resize!(cols, rows)
45
+ }
46
+ i.write out_file
47
+ }
48
+ }
49
+
50
+ puts "Test 1: resize a normal image"
51
+ bm(12) { |x|
52
+ x.report("mini", &test_mini)
53
+ x.report("quick", &test_quick)
54
+ x.report("rmagick", &test_r)
55
+ }
56
+
57
+ ##################################################
58
+
59
+ in_file = File.join($base_dir, '9.gif')
60
+ out_file = File.join($base_dir, 'testout.gif')
61
+
62
+ test_quick = lambda {
63
+ i = QuickMagick::Image.read(in_file).first
64
+ i.resize "8190x8190>"
65
+ i.save out_file
66
+ }
67
+
68
+ test_mini = lambda {
69
+ i = MiniMagick::Image.from_file(in_file)
70
+ i.combine_options do |c|
71
+ c.resize "8190x8190>"
72
+ c.format "gif"
73
+ end
74
+ i.write out_file
75
+ }
76
+
77
+ test_r = lambda {
78
+ i = Magick::Image.read(in_file).first
79
+ i = i.change_geometry!('8190x8190>') { |cols, rows, img|
80
+ img.resize!(cols, rows)
81
+ }
82
+ i.write out_file
83
+ }
84
+
85
+ puts "Test 2: resize a large image"
86
+ bm(12) { |x|
87
+ x.report("mini", &test_mini)
88
+ x.report("quick", &test_quick)
89
+ # Don't try RMagick! You'll regret that ... a lot :'(
90
+ # x.report("rmagick", &test_r)
91
+ }
92
+
93
+ ##################################################
94
+
95
+ class String
96
+ CHARS = ("a".."z").to_a + ("1".."9").to_a
97
+ def self.random(length)
98
+ Array.new(length, '').collect{CHARS[rand(CHARS.size)]}.join
99
+ end
100
+ end
101
+
102
+ def generate_captcha(length, width, height)
103
+ captcha = []
104
+ String.random(6).chars.each_with_index do |c, i|
105
+ letter = {}
106
+ letter[:char] = c
107
+ letter[:x] = width * i / length + (rand - 0.5) * width / length / 8
108
+ letter[:y] = height / 5 + (rand - 0.5) * height / 2
109
+ letter[:sx] = rand * 90 - 45
110
+ letter[:bx] = width * i / length + (rand - 0.5) * width / length / 2
111
+ letter[:by] = height / 2 + (rand - 0.5) * height
112
+ captcha << letter
113
+ end
114
+ captcha
115
+ end
116
+
117
+ out_file = File.join($base_dir, 'captcha.gif')
118
+
119
+ test_quick = lambda {
120
+ i = QuickMagick::Image.solid(290, 70, :white)
121
+ i.bordercolor = :black
122
+ i.border = 5
123
+ i.fill = :black
124
+ i.stroke = :black
125
+ i.strokewidth = 1
126
+ i.pointsize = 40
127
+ i.gravity = :northwest
128
+ captcha = generate_captcha(6, 290, 70)
129
+ captcha.each do |letter|
130
+ i.draw_text letter[:x], letter[:y], letter[:char], :skewx=>letter[:sx]
131
+ end
132
+ i.save out_file
133
+ }
134
+
135
+ test_mini = lambda {
136
+ }
137
+
138
+ test_r = lambda {
139
+ i = Magick::Image.new(290, 70)
140
+ gc = Magick::Draw.new
141
+ i.border! 5, 5, "black"
142
+ gc.stroke "black"
143
+ gc.stroke_width 1
144
+ gc.pointsize 40
145
+ gc.gravity = Magick::NorthWestGravity
146
+ captcha = generate_captcha(6, 290, 70)
147
+ captcha.each do |letter|
148
+ gc.skewx letter[:sx]
149
+ gc.text letter[:x], letter[:y], letter[:char]
150
+ end
151
+ gc.fill "none"
152
+ gc.draw i
153
+ i.write out_file
154
+ }
155
+
156
+ puts "Test 3: generate random captchas"
157
+ bm(12) { |x|
158
+ # x.report("mini", &test_mini)
159
+ x.report("quick", &test_quick)
160
+ x.report("rmagick", &test_r)
161
+ }
162
+ # Cleanup temp files
163
+ ensure
164
+ %w{captcha.gif testout.gif logo.png}.each do |filename|
165
+ fullname = File.join($base_dir, filename)
166
+ File.delete(fullname) if File.exists?(fullname)
167
+ end
168
+ end
169
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aseldawy-quick_magick
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.0
5
+ platform: ruby
6
+ authors:
7
+ - Ahmed ElDawy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-16 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: QuickMagick allows you to access ImageMagick command line functions using Ruby interface.
17
+ email: ahmed.eldawy@badrit.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ - lib/quick_magick/image.rb
25
+ - lib/quick_magick/image_list.rb
26
+ - lib/quick_magick.rb
27
+ files:
28
+ - README
29
+ - Rakefile
30
+ - lib/quick_magick/image.rb
31
+ - lib/quick_magick/image_list.rb
32
+ - lib/quick_magick.rb
33
+ - Manifest
34
+ - quick_magick.gemspec
35
+ - test/image_test.rb
36
+ - test/badfile.xxx
37
+ - test/multipage.tif
38
+ - test/image_list_test.rb
39
+ - test/test_magick.rb
40
+ - test/9.gif
41
+ has_rdoc: false
42
+ homepage: http://quickmagick.rubyforge.org/
43
+ licenses:
44
+ post_install_message:
45
+ rdoc_options:
46
+ - --line-numbers
47
+ - --inline-source
48
+ - --title
49
+ - Quick_magick
50
+ - --main
51
+ - README
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "1.2"
65
+ version:
66
+ requirements: []
67
+
68
+ rubyforge_project: quickmagick
69
+ rubygems_version: 1.3.5
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: QuickMagick allows you to access ImageMagick command line functions using Ruby interface.
73
+ test_files:
74
+ - test/image_test.rb
75
+ - test/image_list_test.rb
76
+ - test/test_magick.rb