quick_magick 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of quick_magick might be problematic. Click here for more details.
- data/Manifest +6 -6
- data/README +13 -4
- data/Rakefile +1 -1
- data/lib/quick_magick/image.rb +45 -14
- data/quick_magick.gemspec +4 -4
- data/test/image_test.rb +21 -0
- data/test/warnings.tiff +0 -0
- metadata +10 -9
data/Manifest
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
+
Manifest
|
1
2
|
README
|
2
3
|
Rakefile
|
4
|
+
lib/quick_magick.rb
|
3
5
|
lib/quick_magick/image.rb
|
4
6
|
lib/quick_magick/image_list.rb
|
5
|
-
|
6
|
-
Manifest
|
7
|
-
quick_magick.gemspec
|
8
|
-
test/image_test.rb
|
7
|
+
test/9.gif
|
9
8
|
test/badfile.xxx
|
10
|
-
test/multipage.tif
|
11
9
|
test/image_list_test.rb
|
10
|
+
test/image_test.rb
|
11
|
+
test/multipage.tif
|
12
12
|
test/test_magick.rb
|
13
|
-
test/
|
13
|
+
test/warnings.tiff
|
data/README
CHANGED
@@ -66,7 +66,7 @@ Actually, I didn't need this feature, but I may need it in the future.
|
|
66
66
|
|
67
67
|
At this point I decided to make my own gem and QuickMagick was born.
|
68
68
|
I addressed the problems of MiniMagick while using the same main idea.
|
69
|
-
First, QuickMagick doesn't write any temporary
|
69
|
+
First, QuickMagick doesn't write any temporary image files to disk.
|
70
70
|
It doesn't issue any command line commands till the very end when you are saving the image.
|
71
71
|
Second, I made an API similar to RMagick which allows for accessing multipage images.
|
72
72
|
Third, I added API commands to create images from scratch and drawing simple primitives on images.
|
@@ -107,9 +107,9 @@ I couldn't test MiniMagick for this because it doesn't support an API for drawin
|
|
107
107
|
|
108
108
|
== Conclusion
|
109
109
|
QuickMagick is very easy to install, very easy to use and allows you to access most features of ImageMagick.
|
110
|
-
RMagick is a bit faster
|
110
|
+
RMagick is a bit faster but it's a bit hard to install.
|
111
111
|
Also RMagick sometimes fail when it tries to handle large images.
|
112
|
-
MiniMagick is proved to be
|
112
|
+
MiniMagick is proved to be slower than QuickMagick with no advantage.
|
113
113
|
So, it's better to use QuickMagick when your application is not image-centric.
|
114
114
|
This means, you're not going to build an image manipulation tool or something like this.
|
115
115
|
For normal operations like resize, rotate, generating captchas ... etc, QuickMagick will be a good friend of you.
|
@@ -161,7 +161,7 @@ QuickMagick supports also ImageList s
|
|
161
161
|
il.resize "300x300>"
|
162
162
|
il.save!
|
163
163
|
|
164
|
-
|
164
|
+
You can also create images from scratch
|
165
165
|
# Create a 300x300 gradient image from yellow to red
|
166
166
|
i1 = QuickMagick::Image::gradient(300, 300, QuickMagick::RadialGradient, :yellow, :red)
|
167
167
|
i1.save 'gradient.png'
|
@@ -178,6 +178,15 @@ QuickMagick supports also ImageList s
|
|
178
178
|
|
179
179
|
... you can then convert it to blob using
|
180
180
|
i.to_blob
|
181
|
+
|
182
|
+
(new) You can now access single pixels using QuickMagick
|
183
|
+
# Create a 300x300 gradient image from yellow to red
|
184
|
+
i1 = QuickMagick::Image::gradient(300, 300, QuickMagick::RadialGradient, :yellow, :red)
|
185
|
+
i1.save 'gradient.png'
|
186
|
+
|
187
|
+
# Now you can access single pixel values
|
188
|
+
i1.get_pixel(10,10) # [255, 0, 0]
|
189
|
+
i1.get_pixel(50,50) # [255, 15, 0]
|
181
190
|
|
182
191
|
For more information on drawing API visit:
|
183
192
|
http://www.imagemagick.org/Usage/draw/
|
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('quick_magick', '0.
|
5
|
+
Echoe.new('quick_magick', '0.7.0') do |p|
|
6
6
|
p.description = "QuickMagick allows you to access ImageMagick command line functions using Ruby interface."
|
7
7
|
p.url = "http://quickmagick.rubyforge.org/"
|
8
8
|
p.author = "Ahmed ElDawy"
|
data/lib/quick_magick/image.rb
CHANGED
@@ -19,12 +19,8 @@ module QuickMagick
|
|
19
19
|
info = identify(%Q<"#{filename}">)
|
20
20
|
info_lines = info.split(/[\r\n]/)
|
21
21
|
images = []
|
22
|
-
|
23
|
-
images << Image.new(filename,
|
24
|
-
else
|
25
|
-
info_lines.each_with_index do |info_line, i|
|
26
|
-
images << Image.new("#{filename}[#{i.to_s}]", info_line)
|
27
|
-
end
|
22
|
+
info_lines.each_with_index do |info_line, i|
|
23
|
+
images << Image.new("#{filename}", i, info_line)
|
28
24
|
end
|
29
25
|
images.each(&proc) if block_given?
|
30
26
|
return images
|
@@ -38,7 +34,7 @@ module QuickMagick
|
|
38
34
|
template_name = type + ":"
|
39
35
|
template_name << color1.to_s if color1
|
40
36
|
template_name << '-' << color2.to_s if color2
|
41
|
-
i = self.new(template_name, nil, true)
|
37
|
+
i = self.new(template_name, 0, nil, true)
|
42
38
|
i.size = QuickMagick::geometry(width, height)
|
43
39
|
i
|
44
40
|
end
|
@@ -47,7 +43,7 @@ module QuickMagick
|
|
47
43
|
def solid(width, height, color=nil)
|
48
44
|
template_name = QuickMagick::SolidColor+":"
|
49
45
|
template_name << color.to_s if color
|
50
|
-
i = self.new(template_name, nil, true)
|
46
|
+
i = self.new(template_name, 0, nil, true)
|
51
47
|
i.size = QuickMagick::geometry(width, height)
|
52
48
|
i
|
53
49
|
end
|
@@ -56,7 +52,7 @@ module QuickMagick
|
|
56
52
|
def pattern(width, height, pattern)
|
57
53
|
raise QuickMagick::QuickMagickError, "Invalid pattern '#{pattern.to_s}'" unless QuickMagick::Patterns.include?(pattern.to_s)
|
58
54
|
template_name = "pattern:#{pattern.to_s}"
|
59
|
-
i = self.new(template_name, nil, true)
|
55
|
+
i = self.new(template_name, 0, nil, true)
|
60
56
|
i.size = QuickMagick::geometry(width, height)
|
61
57
|
i
|
62
58
|
end
|
@@ -86,10 +82,15 @@ module QuickMagick
|
|
86
82
|
@last_is_draw = false
|
87
83
|
self
|
88
84
|
end
|
85
|
+
|
86
|
+
# append the given string as is. Used to append special arguments like +antialias or +debug
|
87
|
+
def append_basic(arg)
|
88
|
+
@arguments << arg << ' '
|
89
|
+
end
|
89
90
|
|
90
91
|
# Image settings supported by ImageMagick
|
91
92
|
IMAGE_SETTINGS_METHODS = %w{
|
92
|
-
adjoin affine alpha
|
93
|
+
adjoin affine alpha authenticate attenuate background bias black-point-compensation
|
93
94
|
blue-primary bordercolor caption channel colors colorspace comment compose compress define
|
94
95
|
delay depth display dispose dither encoding endian family fill filter font format fuzz gravity
|
95
96
|
green-primary intent interlace interpolate interword-spacing kerning label limit loop mask
|
@@ -140,7 +141,7 @@ module QuickMagick
|
|
140
141
|
|
141
142
|
# methods that are called with (=)
|
142
143
|
WITH_EQUAL_METHODS =
|
143
|
-
%w{alpha
|
144
|
+
%w{alpha background bias black-point-compensation blue-primary border bordercolor caption
|
144
145
|
cahnnel colors colorspace comment compose compress depth density encoding endian family fill filter
|
145
146
|
font format frame fuzz geometry gravity label mattecolor page pointsize quality stroke strokewidth
|
146
147
|
undercolor units weight
|
@@ -149,10 +150,14 @@ module QuickMagick
|
|
149
150
|
# methods that takes geometry options
|
150
151
|
WITH_GEOMETRY_METHODS =
|
151
152
|
%w{density page sampling-factor size tile-offset adaptive-blur adaptive-resize adaptive-sharpen
|
152
|
-
annotate blur border chop contrast-stretch extent extract
|
153
|
+
annotate blur border chop contrast-stretch extent extract frame gaussian-blur
|
153
154
|
geometry lat linear-stretch liquid-rescale motion-blur region repage resample resize roll
|
154
155
|
sample scale selective-blur shadow sharpen shave shear sigmoidal-contrast sketch
|
155
156
|
splice thumbnail unsharp vignette wave crop}
|
157
|
+
|
158
|
+
# Methods that need special treatment. This array is used just to keep track of them.
|
159
|
+
SPECIAL_COMMANDS =
|
160
|
+
%w{floodfill antialias draw}
|
156
161
|
|
157
162
|
IMAGE_SETTINGS_METHODS.each do |method|
|
158
163
|
if WITH_EQUAL_METHODS.include?(method)
|
@@ -191,13 +196,19 @@ module QuickMagick
|
|
191
196
|
append_to_operators "floodfill", QuickMagick::geometry(width, height, x, y, flag), color
|
192
197
|
end
|
193
198
|
|
199
|
+
# Enables/Disables flood fill. Pass a boolean argument.
|
200
|
+
def antialias=(flag)
|
201
|
+
append_basic flag ? '-antialias' : '+antialias'
|
202
|
+
end
|
203
|
+
|
194
204
|
# define attribute readers (getters)
|
195
205
|
attr_reader :image_filename
|
196
206
|
alias original_filename image_filename
|
197
207
|
|
198
208
|
# constructor
|
199
|
-
def initialize(filename, info_line=nil, pseudo_image=false)
|
209
|
+
def initialize(filename, index=0, info_line=nil, pseudo_image=false)
|
200
210
|
@image_filename = filename
|
211
|
+
@index = index
|
201
212
|
@pseudo_image = pseudo_image
|
202
213
|
if info_line
|
203
214
|
@image_infoline = info_line.split
|
@@ -208,7 +219,7 @@ module QuickMagick
|
|
208
219
|
|
209
220
|
# The command line so far that will be used to convert or save the image
|
210
221
|
def command_line
|
211
|
-
%Q< "(" #{@arguments} #{QuickMagick::c
|
222
|
+
%Q< "(" #{@arguments} #{QuickMagick::c(image_filename + (@pseudo_image ? "" : "[#{@index}]"))} ")" >
|
212
223
|
end
|
213
224
|
|
214
225
|
# An information line about the image obtained using 'identify' command line
|
@@ -463,6 +474,26 @@ module QuickMagick
|
|
463
474
|
File.size?(image_filename)
|
464
475
|
end
|
465
476
|
|
477
|
+
# Reads a pixel from the image.
|
478
|
+
# WARNING: This is done through command line which is very slow.
|
479
|
+
# It is not recommended at all to use this method for image processing for example.
|
480
|
+
def get_pixel(x, y)
|
481
|
+
error_file = Tempfile.new('identify_error')
|
482
|
+
result = `identify -verbose -crop #{QuickMagick::geometry(1,1,x,y)} #{QuickMagick::c(image_filename)}[#{@index}] 2>'#{error_file.path}'`
|
483
|
+
unless $?.success?
|
484
|
+
error_message = <<-ERROR
|
485
|
+
Error executing command: identify #{image_filename}
|
486
|
+
Result is: #{result}
|
487
|
+
Error is: #{error_file.read}
|
488
|
+
ERROR
|
489
|
+
raise QuickMagick::QuickMagickError, error_message
|
490
|
+
end
|
491
|
+
result =~ /Histogram:\s*\d+:\s*\(\s*(\d+),\s*(\d+),\s*(\d+)\)/
|
492
|
+
return [$1.to_i, $2.to_i, $3.to_i]
|
493
|
+
ensure
|
494
|
+
error_file.close
|
495
|
+
end
|
496
|
+
|
466
497
|
# displays the current image as animated image
|
467
498
|
def animate
|
468
499
|
`animate #{command_line}`
|
data/quick_magick.gemspec
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{quick_magick}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.7.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Ahmed ElDawy"]
|
9
|
-
s.date = %q{2009-
|
9
|
+
s.date = %q{2009-11-16}
|
10
10
|
s.description = %q{QuickMagick allows you to access ImageMagick command line functions using Ruby interface.}
|
11
11
|
s.email = %q{ahmed.eldawy@badrit.com}
|
12
|
-
s.extra_rdoc_files = ["README", "lib/quick_magick
|
13
|
-
s.files = ["README", "Rakefile", "lib/quick_magick
|
12
|
+
s.extra_rdoc_files = ["README", "lib/quick_magick.rb", "lib/quick_magick/image.rb", "lib/quick_magick/image_list.rb"]
|
13
|
+
s.files = ["Manifest", "README", "Rakefile", "lib/quick_magick.rb", "lib/quick_magick/image.rb", "lib/quick_magick/image_list.rb", "test/9.gif", "test/badfile.xxx", "test/image_list_test.rb", "test/image_test.rb", "test/multipage.tif", "test/test_magick.rb", "test/warnings.tiff", "quick_magick.gemspec"]
|
14
14
|
s.homepage = %q{http://quickmagick.rubyforge.org/}
|
15
15
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Quick_magick", "--main", "README"]
|
16
16
|
s.require_paths = ["lib"]
|
data/test/image_test.rb
CHANGED
@@ -302,4 +302,25 @@ class ImageTest < Test::Unit::TestCase
|
|
302
302
|
# Now it's non pseudo
|
303
303
|
i.save!
|
304
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
|
+
end
|
315
|
+
|
316
|
+
def test_get_pixel
|
317
|
+
image = QuickMagick::Image.read(@logo_filename)[0]
|
318
|
+
assert_equal [2,90,164], image.get_pixel(356, 286)
|
319
|
+
end
|
320
|
+
|
321
|
+
def test_get_pixel_with_multipage
|
322
|
+
image_filename = File.join($base_dir, "multipage.tif")
|
323
|
+
image = QuickMagick::Image.read(image_filename)[1]
|
324
|
+
assert_equal [234,43,44], image.get_pixel(256,73)
|
325
|
+
end
|
305
326
|
end
|
data/test/warnings.tiff
ADDED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quick_magick
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ahmed ElDawy
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-11-16 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -21,23 +21,24 @@ extensions: []
|
|
21
21
|
|
22
22
|
extra_rdoc_files:
|
23
23
|
- README
|
24
|
+
- lib/quick_magick.rb
|
24
25
|
- lib/quick_magick/image.rb
|
25
26
|
- lib/quick_magick/image_list.rb
|
26
|
-
- lib/quick_magick.rb
|
27
27
|
files:
|
28
|
+
- Manifest
|
28
29
|
- README
|
29
30
|
- Rakefile
|
31
|
+
- lib/quick_magick.rb
|
30
32
|
- lib/quick_magick/image.rb
|
31
33
|
- lib/quick_magick/image_list.rb
|
32
|
-
-
|
33
|
-
- Manifest
|
34
|
-
- quick_magick.gemspec
|
35
|
-
- test/image_test.rb
|
34
|
+
- test/9.gif
|
36
35
|
- test/badfile.xxx
|
37
|
-
- test/multipage.tif
|
38
36
|
- test/image_list_test.rb
|
37
|
+
- test/image_test.rb
|
38
|
+
- test/multipage.tif
|
39
39
|
- test/test_magick.rb
|
40
|
-
- test/
|
40
|
+
- test/warnings.tiff
|
41
|
+
- quick_magick.gemspec
|
41
42
|
has_rdoc: true
|
42
43
|
homepage: http://quickmagick.rubyforge.org/
|
43
44
|
licenses: []
|