quick_magick_hooopo 0.8.1

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
@@ -0,0 +1,17 @@
1
+ require 'test/unit'
2
+ require 'quick_magick'
3
+
4
+ $base_dir = File.dirname(File.expand_path(__FILE__))
5
+
6
+ class QuickMagickTest < Test::Unit::TestCase
7
+ def test_escape_commandline
8
+ [
9
+ ["good_file_name.png", "good_file_name.png"],
10
+ ["filename with spaces.png", '"filename with spaces.png"'],
11
+ ["filename_with_$pec!als.jpg", '"filename_with_$pec!als.jpg"']
12
+ ].each do |filename, escaped_filename|
13
+ assert_equal escaped_filename, QuickMagick::c(filename)
14
+ end
15
+
16
+ end
17
+ end
Binary file
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: quick_magick_hooopo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ahmed ElDawy
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-18 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: QuickMagick allows you to access ImageMagick command line functions using
15
+ Ruby interface.
16
+ email: ahmed.eldawy@badrit.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files:
20
+ - README.rdoc
21
+ - lib/quick_magick.rb
22
+ - lib/quick_magick/image.rb
23
+ - lib/quick_magick/image_list.rb
24
+ files:
25
+ - Manifest
26
+ - README.rdoc
27
+ - Rakefile
28
+ - lib/quick_magick.rb
29
+ - lib/quick_magick/image.rb
30
+ - lib/quick_magick/image_list.rb
31
+ - quick_magick_hooopo.gemspec
32
+ - test/9.gif
33
+ - test/badfile.xxx
34
+ - test/image_list_test.rb
35
+ - test/image_test.rb
36
+ - test/multipage.tif
37
+ - test/test_magick.rb
38
+ - test/test_quick_magick.rb
39
+ - test/warnings.tiff
40
+ homepage: http://quickmagick.rubyforge.org/
41
+ licenses: []
42
+ post_install_message:
43
+ rdoc_options:
44
+ - --line-numbers
45
+ - --inline-source
46
+ - --title
47
+ - Quick_magick_hooopo
48
+ - --main
49
+ - README.rdoc
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '1.2'
64
+ requirements: []
65
+ rubyforge_project: quickmagick
66
+ rubygems_version: 1.8.11
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: A gem build by BadrIT to access ImageMagick command line functions easily
70
+ and quickly
71
+ test_files:
72
+ - test/test_quick_magick.rb
73
+ - test/image_test.rb
74
+ - test/image_list_test.rb
75
+ - test/test_magick.rb