quick_magick 0.1.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.
Potentially problematic release.
This version of quick_magick might be problematic. Click here for more details.
- data/Manifest +13 -0
- data/README +64 -0
- data/Rakefile +14 -0
- data/lib/quick_magick/image.rb +252 -0
- data/lib/quick_magick/image_list.rb +60 -0
- data/lib/quick_magick.rb +32 -0
- data/quick_magick.gemspec +32 -0
- data/test/badfile.xxx +0 -0
- data/test/image_list_test.rb +84 -0
- data/test/image_test.rb +125 -0
- data/test/imagemagick-logo.png +0 -0
- data/test/logo-small.jpg +0 -0
- data/test/multipage.tif +0 -0
- metadata +74 -0
data/Manifest
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
README
|
2
|
+
Rakefile
|
3
|
+
lib/quick_magick/image.rb
|
4
|
+
lib/quick_magick/image_list.rb
|
5
|
+
lib/quick_magick.rb
|
6
|
+
Manifest
|
7
|
+
quick_magick.gemspec
|
8
|
+
test/image_test.rb
|
9
|
+
test/logo-small.jpg
|
10
|
+
test/badfile.xxx
|
11
|
+
test/multipage.tif
|
12
|
+
test/image_list_test.rb
|
13
|
+
test/imagemagick-logo.png
|
data/README
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
== QuickMagick
|
2
|
+
|
3
|
+
QuickMagick is a gem for easily accessing ImageMagick command line tools from Ruby programs.
|
4
|
+
|
5
|
+
== What is different?
|
6
|
+
|
7
|
+
But what's different from other gems like RMagick and mini-magick?
|
8
|
+
RMagick is a very good gem and QuickMagick is not a replacement of it.
|
9
|
+
RMagick mainpulates images in memory.
|
10
|
+
This is sometimes preferable but not in all cases.
|
11
|
+
It uses a huge amonut of memory when manipulating images of large sizes.
|
12
|
+
QuickMagick allows you to access all the powerful commands of ImageMagick that are accessible from command line.
|
13
|
+
When you need more advanced options like reading pixel values, you should go to RMagick.
|
14
|
+
|
15
|
+
The idea of this gem came from mini-magick.
|
16
|
+
I used mini-magick for a little time but I found that some advanced options are missing.
|
17
|
+
For example, you cannot manipulate multipage images.
|
18
|
+
Also, it uses "mogrify" and creates temporary files to simulate the "convert" command which makes it slower as it accesses the disk multiple times.
|
19
|
+
Another small stuf is that it relies on method_missing to set command line arguments which is slow and not preferable.
|
20
|
+
|
21
|
+
In QuickMagick I tried to solve the above problems while keeping the API as easy as possible.
|
22
|
+
|
23
|
+
== Examples
|
24
|
+
|
25
|
+
Determine image information
|
26
|
+
i = QuickMagick::Image.read('test.jpg').first
|
27
|
+
i.width # Retrieves width in pixels
|
28
|
+
i.height # Retrieves height in pixels
|
29
|
+
|
30
|
+
Resize and image
|
31
|
+
i = QuickMagick::Image.read('test.jpg').first
|
32
|
+
i.resize "300x300!"
|
33
|
+
i.save "resized_image.jpg"
|
34
|
+
|
35
|
+
or
|
36
|
+
i.append_to_args 'resize', "300x300!"
|
37
|
+
|
38
|
+
or
|
39
|
+
i.resize 300, 300, nil, nil, QuickMagick::AspectGeometry
|
40
|
+
|
41
|
+
|
42
|
+
Access multipage image
|
43
|
+
i = QuickMagick::Image.read("multipage.pdf") {|image| image.density = 300}
|
44
|
+
i.size % number of pages
|
45
|
+
i.each_with_index do |page, i|
|
46
|
+
i.save "page_#{i}.jpg"
|
47
|
+
end
|
48
|
+
|
49
|
+
From blob
|
50
|
+
i = QuickMagick::Image.from_blob(blob_data).first
|
51
|
+
i.sample "100x100!"
|
52
|
+
i.save
|
53
|
+
|
54
|
+
Modify a file (mogrify)
|
55
|
+
i = QuickMagick::Image.read('test.jpg')
|
56
|
+
i.resize "100x100!"
|
57
|
+
i.save!
|
58
|
+
|
59
|
+
You can also display an image to Xserver
|
60
|
+
i = QuickMagick::Image.read('test.jpg')
|
61
|
+
i.display
|
62
|
+
|
63
|
+
Check all command line options of ImageMagick at
|
64
|
+
http://www.imagemagick.org/script/convert.php
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('quick_magick', '0.1.0') do |p|
|
6
|
+
p.description = "QuickMagick allows you to access ImageMagick command line functions using Ruby interface."
|
7
|
+
p.url = "http://quickmagick.rubyforge.org/"
|
8
|
+
p.author = "Ahmed ElDawy"
|
9
|
+
p.email = "ahmed.eldawy@badrit.com"
|
10
|
+
p.project = "quickmagick"
|
11
|
+
end
|
12
|
+
|
13
|
+
#Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
14
|
+
|
@@ -0,0 +1,252 @@
|
|
1
|
+
require "tempfile"
|
2
|
+
|
3
|
+
module QuickMagick
|
4
|
+
|
5
|
+
class Image
|
6
|
+
class <<self
|
7
|
+
|
8
|
+
# create an array of images from the given blob data
|
9
|
+
def from_blob(blob, &proc)
|
10
|
+
file = Tempfile.new(QuickMagick::random_string)
|
11
|
+
file.write(blob)
|
12
|
+
file.close
|
13
|
+
self.read(file.path, &proc)
|
14
|
+
end
|
15
|
+
|
16
|
+
# create an array of images from the given file
|
17
|
+
def read(filename, &proc)
|
18
|
+
info = identify(%Q<"#{filename}">)
|
19
|
+
if info.empty?
|
20
|
+
raise QuickMagick::QuickMagickError, "Illegal file \"#{filename}\""
|
21
|
+
end
|
22
|
+
info_lines = info.split(/[\r\n]/)
|
23
|
+
images = []
|
24
|
+
if info_lines.size == 1
|
25
|
+
images << Image.new(filename, info_lines.first)
|
26
|
+
else
|
27
|
+
info_lines.each_with_index do |info_line, i|
|
28
|
+
images << Image.new("#{filename}[#{i.to_s}]", info_line)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
images.collect!(&proc)
|
32
|
+
return images
|
33
|
+
end
|
34
|
+
|
35
|
+
alias open read
|
36
|
+
|
37
|
+
def gradient(width, height, type=QuickMagick::LinearGradient, color1=nil, color2=nil)
|
38
|
+
template_name = type + ":"
|
39
|
+
template_name << color1.to_s if color1
|
40
|
+
template_name << '-' << color2.to_s if color2
|
41
|
+
i = self.new(template_name, nil, true)
|
42
|
+
i.size = QuickMagick::Image::retrieve_geometry(width, height)
|
43
|
+
i
|
44
|
+
end
|
45
|
+
|
46
|
+
# Creates an image with solid color
|
47
|
+
def solid(width, height, color=nil)
|
48
|
+
template_name = QuickMagick::SolidColor+":"
|
49
|
+
template_name << color.to_s if color
|
50
|
+
i = self.new(template_name, nil, true)
|
51
|
+
i.size = QuickMagick::Image::retrieve_geometry(width, height)
|
52
|
+
i
|
53
|
+
end
|
54
|
+
|
55
|
+
# Creates an image from pattern
|
56
|
+
def pattern(width, height, pattern)
|
57
|
+
raise QuickMagick::QuickMagickError, "Invalid pattern '#{pattern.to_s}'" unless QuickMagick::Patterns.include?(pattern.to_s)
|
58
|
+
template_name = "pattern:#{pattern.to_s}"
|
59
|
+
i = self.new(template_name, nil, true)
|
60
|
+
i.size = QuickMagick::Image::retrieve_geometry(width, height)
|
61
|
+
i
|
62
|
+
end
|
63
|
+
|
64
|
+
# returns info for an image using <code>identify</code> command
|
65
|
+
def identify(filename)
|
66
|
+
`identify #{filename}`
|
67
|
+
end
|
68
|
+
|
69
|
+
def retrieve_geometry(width, height=nil, x=nil, y=nil, flag=nil)
|
70
|
+
geometry_string = ""
|
71
|
+
geometry_string << width.to_s if width
|
72
|
+
geometry_string << 'x' << height.to_s if height
|
73
|
+
geometry_string << '+' << x.to_s if x
|
74
|
+
geometry_string << '+' << y.to_s if y
|
75
|
+
geometry_string << flag if flag
|
76
|
+
geometry_string
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# append the given option, value pair to the args for the current image
|
81
|
+
def append_to_operators(arg, value="")
|
82
|
+
@operators << %Q<-#{arg} #{value}>
|
83
|
+
end
|
84
|
+
|
85
|
+
# append the given option, value pair to the settings of the current image
|
86
|
+
def append_to_settings(arg, value="")
|
87
|
+
@settings << %Q<-#{arg} #{value}>
|
88
|
+
end
|
89
|
+
|
90
|
+
IMAGE_SETTINGS_METHODS = %w{
|
91
|
+
adjoin affine alpha antialias authenticate attenuate background bias black-point-compensation
|
92
|
+
blue-primary bordercolor caption channel colors colorspace comment compose compress define
|
93
|
+
delay depth display dispose dither encoding endian family fill filter font format fuzz gravity
|
94
|
+
green-primary intent interlace interpolate interword-spacing kerning label limit loop mask
|
95
|
+
mattecolor monitor orient ping pointsize preview quality quiet red-primary regard-warnings
|
96
|
+
remap respect-parentheses scene seed stretch stroke strokewidth style taint texture treedepth
|
97
|
+
transparent-color undercolor units verbose view virtual-pixel weight white-point
|
98
|
+
|
99
|
+
density page sampling-factor size tile-offset
|
100
|
+
}
|
101
|
+
|
102
|
+
IMAGE_OPERATORS_METHODS = %w{
|
103
|
+
alpha auto-orient bench black-threshold bordercolor charcoal clip clip-mask clip-path colorize
|
104
|
+
contrast convolve cycle decipher deskew despeckle distort draw edge encipher emboss enhance equalize
|
105
|
+
evaluate flip flop function gamma identify implode layers level level-colors median modulate monochrome
|
106
|
+
negate noise normalize opaque ordered-dither NxN paint polaroid posterize print profile quantize
|
107
|
+
radial-blur Raise random-threshold recolor render rotate segment sepia-tone set shade solarize
|
108
|
+
sparse-color spread strip swirl threshold tile tint transform transparent transpose transverse trim
|
109
|
+
type unique-colors white-threshold
|
110
|
+
|
111
|
+
adaptive-blur adaptive-resize adaptive-sharpen annotate blur border chop contrast-stretch extent
|
112
|
+
extract frame gaussian-blur geometry lat linear-stretch liquid-rescale motion-blur region repage
|
113
|
+
resample resize roll sample scale selective-blur shadow sharpen shave shear sigmoidal-contrast
|
114
|
+
sketch splice thumbnail unsharp vignette wave
|
115
|
+
|
116
|
+
append average clut coalesce combine composite deconstruct flatten fx hald-clut morph mosaic process reverse separate write
|
117
|
+
crop
|
118
|
+
}
|
119
|
+
|
120
|
+
def floodfill(width, height=nil, x=nil, y=nil, flag=nil, color=nil)
|
121
|
+
# TODO do a special method for floodfill
|
122
|
+
end
|
123
|
+
|
124
|
+
WITH_EQUAL_METHODS =
|
125
|
+
%w{alpha antialias background bias black-point-compensation blue-primary border bordercolor caption
|
126
|
+
cahnnel colors colorspace comment compose compress depth density encoding endian family fill filter
|
127
|
+
font format frame fuzz geometry gravity label mattecolor page pointsize quality undercolor units weight
|
128
|
+
brodercolor transparent type size}
|
129
|
+
|
130
|
+
WITH_GEOMETRY_METHODS =
|
131
|
+
%w{density page sampling-factor size tile-offset adaptive-blur adaptive-resize adaptive-sharpen
|
132
|
+
annotate blur border chop contrast-stretch extent extract floodfill frame gaussian-blur
|
133
|
+
geometry lat linear-stretch liquid-rescale motion-blur region repage resample resize roll
|
134
|
+
sample scale selective-blur shadow sharpen shave shear sigmoidal-contrast sketch
|
135
|
+
splice thumbnail unsharp vignette wave crop}
|
136
|
+
|
137
|
+
IMAGE_SETTINGS_METHODS.each do |method|
|
138
|
+
if WITH_EQUAL_METHODS.include?(method)
|
139
|
+
define_method((method+'=').to_sym) do |arg|
|
140
|
+
append_to_settings(method, %Q<"#{arg}"> )
|
141
|
+
end
|
142
|
+
elsif WITH_GEOMETRY_METHODS.include?(method)
|
143
|
+
define_method((method).to_sym) do |*args|
|
144
|
+
append_to_settings(method, %Q<"#{QuickMagick::Image.retrieve_geometry(*args) }"> )
|
145
|
+
end
|
146
|
+
else
|
147
|
+
define_method(method.to_sym) do |*args|
|
148
|
+
append_to_settings(method, args.collect{|arg| %Q<"#{arg}"> }.join(" "))
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
IMAGE_OPERATORS_METHODS.each do |method|
|
154
|
+
if WITH_EQUAL_METHODS.include?(method)
|
155
|
+
define_method((method+'=').to_sym) do |arg|
|
156
|
+
append_to_operators(method, %Q<"#{arg}"> )
|
157
|
+
end
|
158
|
+
elsif WITH_GEOMETRY_METHODS.include?(method)
|
159
|
+
define_method((method).to_sym) do |*args|
|
160
|
+
append_to_operators(method, %Q<"#{QuickMagick::Image.retrieve_geometry(*args) }"> )
|
161
|
+
end
|
162
|
+
else
|
163
|
+
define_method(method.to_sym) do |*args|
|
164
|
+
append_to_operators(method, args.collect{|arg| %Q<"#{arg}"> }.join(" "))
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
# define attribute readers (getters)
|
170
|
+
attr_reader :image_filename
|
171
|
+
alias original_filename image_filename
|
172
|
+
|
173
|
+
# constructor
|
174
|
+
def initialize(filename, info_line=nil, pseudo_image=false)
|
175
|
+
@image_filename = filename
|
176
|
+
@pseudo_image = pseudo_image
|
177
|
+
if info_line
|
178
|
+
@image_infoline = info_line.split
|
179
|
+
@image_infoline[0..1] = @image_infoline[0..1].join(' ') while !@image_infoline[0].start_with?(image_filename)
|
180
|
+
end
|
181
|
+
@operators = ""
|
182
|
+
@settings = ""
|
183
|
+
end
|
184
|
+
|
185
|
+
def command_line
|
186
|
+
%Q<#{@settings} "#{image_filename}" #{@operators}>
|
187
|
+
end
|
188
|
+
|
189
|
+
def image_infoline
|
190
|
+
unless @image_infoline
|
191
|
+
@image_infoline = QuickMagick::Image::identify(command_line).split
|
192
|
+
@image_infoline[0..1] = @image_infoline[0..1].join(' ') while !@image_infoline[0].start_with?(image_filename)
|
193
|
+
end
|
194
|
+
@image_infoline
|
195
|
+
end
|
196
|
+
|
197
|
+
# saves the current image to the given filename
|
198
|
+
def save(output_filename)
|
199
|
+
`convert #{command_line} "#{output_filename}"`
|
200
|
+
end
|
201
|
+
|
202
|
+
alias write save
|
203
|
+
alias convert save
|
204
|
+
|
205
|
+
# saves the current image overwriting the original image file
|
206
|
+
def save!
|
207
|
+
raise QuickMagick::QuickMagickError, "Cannot mogrify a pseudo image" if @pseudo_image
|
208
|
+
`mogrify #{command_line}`
|
209
|
+
end
|
210
|
+
|
211
|
+
alias write! save!
|
212
|
+
alias mogrify! save!
|
213
|
+
|
214
|
+
def format
|
215
|
+
image_infoline[1]
|
216
|
+
end
|
217
|
+
|
218
|
+
def columns
|
219
|
+
image_infoline[2].split('x').first.to_i
|
220
|
+
end
|
221
|
+
|
222
|
+
alias width columns
|
223
|
+
|
224
|
+
def rows
|
225
|
+
image_infoline[2].split('x').last.to_i
|
226
|
+
end
|
227
|
+
|
228
|
+
alias height rows
|
229
|
+
|
230
|
+
def bit_depth
|
231
|
+
image_infoline[4].to_i
|
232
|
+
end
|
233
|
+
|
234
|
+
def colors
|
235
|
+
image_infoline[6].to_i
|
236
|
+
end
|
237
|
+
|
238
|
+
def size
|
239
|
+
File.size?(image_filename)
|
240
|
+
end
|
241
|
+
|
242
|
+
# displays the current image as animated image
|
243
|
+
def animate
|
244
|
+
`animate #{command_line}`
|
245
|
+
end
|
246
|
+
|
247
|
+
# displays the current image to the x-windowing system
|
248
|
+
def display
|
249
|
+
`display #{command_line}`
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
@@ -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
|
data/lib/quick_magick.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# check if ImageMagick is installed
|
2
|
+
status = `identify --version`
|
3
|
+
raise QuickMagick::QuickMagickError "ImageMagick not installed" if status.empty?
|
4
|
+
|
5
|
+
module QuickMagick
|
6
|
+
class QuickMagickError < RuntimeError; end
|
7
|
+
PercentGeometry = "%"
|
8
|
+
AspectGeometry = "!"
|
9
|
+
LessGeometry = "<"
|
10
|
+
GreaterGeometry = ">"
|
11
|
+
AreaGeometry = "@"
|
12
|
+
MinimumGeometry = "^"
|
13
|
+
|
14
|
+
SolidColor = "xc"
|
15
|
+
LinearGradient = "gradient"
|
16
|
+
RadialGradient = "radial-gradient"
|
17
|
+
|
18
|
+
Patterns = %w{bricks checkboard circles crosshatch crosshatch30 crosshatch45 fishscales} +
|
19
|
+
(0..20).collect {|level| "gray#{level}" } +
|
20
|
+
%w{hexagons horizontal horizontalsaw hs_bdiagonal hs_cross hs_diagcross hs_fdiagonal hs_horizontal
|
21
|
+
hs_vertical left30 left45 leftshingle octagons right30 right45 rightshingle smallfishscales
|
22
|
+
vertical verticalbricks verticalleftshingle verticalrightshingle verticalsaw}
|
23
|
+
|
24
|
+
# generate a random string of specified length
|
25
|
+
def self.random_string(length=10)
|
26
|
+
@@CHARS ||= ("a".."z").to_a + ("1".."9").to_a
|
27
|
+
Array.new(length, '').collect{@@CHARS[rand(@@CHARS.size)]}.join
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
require 'quick_magick/image'
|
32
|
+
require 'quick_magick/image_list'
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{quick_magick}
|
5
|
+
s.version = "0.1.0"
|
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 = %q{2009-07-29}
|
10
|
+
s.description = %q{QuickMagick allows you to access ImageMagick command line functions using Ruby interface.}
|
11
|
+
s.email = %q{ahmed.eldawy@badrit.com}
|
12
|
+
s.extra_rdoc_files = ["README", "lib/quick_magick/image.rb", "lib/quick_magick/image_list.rb", "lib/quick_magick.rb"]
|
13
|
+
s.files = ["README", "Rakefile", "lib/quick_magick/image.rb", "lib/quick_magick/image_list.rb", "lib/quick_magick.rb", "Manifest", "quick_magick.gemspec", "test/image_test.rb", "test/logo-small.jpg", "test/badfile.xxx", "test/multipage.tif", "test/image_list_test.rb", "test/imagemagick-logo.png"]
|
14
|
+
s.has_rdoc = true
|
15
|
+
s.homepage = %q{http://quickmagick.rubyforge.org/}
|
16
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Quick_magick", "--main", "README"]
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.rubyforge_project = %q{quickmagick}
|
19
|
+
s.rubygems_version = %q{1.3.1}
|
20
|
+
s.summary = %q{QuickMagick allows you to access ImageMagick command line functions using Ruby interface.}
|
21
|
+
s.test_files = ["test/image_test.rb", "test/image_list_test.rb"]
|
22
|
+
|
23
|
+
if s.respond_to? :specification_version then
|
24
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
25
|
+
s.specification_version = 2
|
26
|
+
|
27
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
28
|
+
else
|
29
|
+
end
|
30
|
+
else
|
31
|
+
end
|
32
|
+
end
|
data/test/badfile.xxx
ADDED
Binary file
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'quick_magick'
|
3
|
+
require 'ftools'
|
4
|
+
|
5
|
+
$base_dir = File.dirname(File.expand_path(__FILE__))
|
6
|
+
|
7
|
+
class ImageTest < Test::Unit::TestCase
|
8
|
+
def test_open_file
|
9
|
+
image_filename = File.join($base_dir, "imagemagick-logo.png")
|
10
|
+
i = QuickMagick::ImageList.new(image_filename)
|
11
|
+
assert_equal 1, i.length
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_save_multipage
|
15
|
+
image_filename = File.join($base_dir, "imagemagick-logo.png")
|
16
|
+
image_filename2 = File.join($base_dir, "logo-small.jpg")
|
17
|
+
i = QuickMagick::ImageList.new(image_filename, image_filename2)
|
18
|
+
assert_equal 2, i.length
|
19
|
+
out_filename = File.join($base_dir, "out.tif")
|
20
|
+
i.save out_filename
|
21
|
+
|
22
|
+
i = QuickMagick::Image.read(out_filename)
|
23
|
+
assert_equal 2, i.length
|
24
|
+
assert_equal 100, i[1].width
|
25
|
+
ensure
|
26
|
+
File.delete(out_filename) if out_filename && File.exists?(out_filename)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_bulk_resize
|
30
|
+
image_filename1 = File.join($base_dir, "imagemagick-logo.png")
|
31
|
+
image_filename2 = File.join($base_dir, "logo-small.jpg")
|
32
|
+
i = QuickMagick::ImageList.new(image_filename1, image_filename2)
|
33
|
+
i.resize "50x50!"
|
34
|
+
out_filename = File.join($base_dir, "out.tif")
|
35
|
+
i.save out_filename
|
36
|
+
|
37
|
+
i = QuickMagick::Image.read(out_filename)
|
38
|
+
assert_equal 2, i.length
|
39
|
+
assert_equal 50, i[0].width
|
40
|
+
assert_equal 50, i[1].width
|
41
|
+
ensure
|
42
|
+
File.delete(out_filename) if out_filename && File.exists?(out_filename)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_append_image
|
46
|
+
image_filename1 = File.join($base_dir, "imagemagick-logo.png")
|
47
|
+
image_filename2 = File.join($base_dir, "logo-small.jpg")
|
48
|
+
i = QuickMagick::ImageList.new
|
49
|
+
i << QuickMagick::Image.read(image_filename1)
|
50
|
+
i << QuickMagick::Image.read(image_filename2)
|
51
|
+
i.resize "50x50!"
|
52
|
+
out_filename = File.join($base_dir, "out.tif")
|
53
|
+
i.save out_filename
|
54
|
+
|
55
|
+
i = QuickMagick::Image.read(out_filename)
|
56
|
+
assert_equal 2, i.length
|
57
|
+
assert_equal 50, i[0].width
|
58
|
+
assert_equal 50, i[1].width
|
59
|
+
ensure
|
60
|
+
File.delete(out_filename) if out_filename && File.exists?(out_filename)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_bulk_convert
|
64
|
+
image_filename1 = File.join($base_dir, "imagemagick-logo.png")
|
65
|
+
image_filename2 = File.join($base_dir, "logo-small.jpg")
|
66
|
+
new_image_filename1 = File.join($base_dir, "temp1.png")
|
67
|
+
new_image_filename2 = File.join($base_dir, "temp2.jpg")
|
68
|
+
File.copy(image_filename1, new_image_filename1)
|
69
|
+
File.copy(image_filename2, new_image_filename2)
|
70
|
+
i = QuickMagick::ImageList.new(new_image_filename1, new_image_filename2)
|
71
|
+
i.format = 'gif'
|
72
|
+
i.save!
|
73
|
+
|
74
|
+
out_filename1 = new_image_filename1.sub('.png', '.gif')
|
75
|
+
out_filename2 = new_image_filename2.sub('.jpg', '.gif')
|
76
|
+
assert File.exists?(out_filename1)
|
77
|
+
assert File.exists?(out_filename2)
|
78
|
+
ensure
|
79
|
+
File.delete(new_image_filename1) if new_image_filename1 && File.exists?(new_image_filename1)
|
80
|
+
File.delete(new_image_filename2) if new_image_filename2 && File.exists?(new_image_filename2)
|
81
|
+
File.delete(out_filename1) if out_filename1 && File.exists?(out_filename1)
|
82
|
+
File.delete(out_filename2) if out_filename2 && File.exists?(out_filename2)
|
83
|
+
end
|
84
|
+
end
|
data/test/image_test.rb
ADDED
@@ -0,0 +1,125 @@
|
|
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
|
+
def test_open_existing_image
|
8
|
+
image_filename = File.join($base_dir, "imagemagick-logo.png")
|
9
|
+
i = QuickMagick::Image.read(image_filename)
|
10
|
+
assert_equal 1, i.size
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_create_from_blob
|
14
|
+
image_filename = File.join($base_dir, "imagemagick-logo.png")
|
15
|
+
blob = nil
|
16
|
+
File.open(image_filename, "rb") do |f|
|
17
|
+
blob = f.read
|
18
|
+
end
|
19
|
+
i = QuickMagick::Image.from_blob(blob)
|
20
|
+
assert_equal 1, i.size
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_image_info
|
24
|
+
image_filename = File.join($base_dir, "imagemagick-logo.png")
|
25
|
+
i = QuickMagick::Image.read(image_filename).first
|
26
|
+
assert_equal 464, i.width
|
27
|
+
assert_equal 479, i.height
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_open_non_existing_file
|
31
|
+
image_filename = File.join($base_dir, "space.png")
|
32
|
+
assert_raises QuickMagick::QuickMagickError do
|
33
|
+
i = QuickMagick::Image.read(image_filename)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_open_bad_file
|
38
|
+
image_filename = File.join($base_dir, "badfile.xxx")
|
39
|
+
assert_raises QuickMagick::QuickMagickError do
|
40
|
+
i = QuickMagick::Image.read(image_filename)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_open_mulitpage_file
|
45
|
+
image_filename = File.join($base_dir, "multipage.tif")
|
46
|
+
i = QuickMagick::Image.read(image_filename)
|
47
|
+
assert_equal 2, i.size
|
48
|
+
assert_equal 100, i[0].width
|
49
|
+
assert_equal 464, i[1].width
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_resize_image
|
53
|
+
image_filename = File.join($base_dir, "imagemagick-logo.png")
|
54
|
+
i = QuickMagick::Image.read(image_filename).first
|
55
|
+
i.resize("300x300!")
|
56
|
+
out_filename = File.join($base_dir, "imagemagick-resized.png")
|
57
|
+
File.delete out_filename if File.exists?(out_filename)
|
58
|
+
i.save(out_filename)
|
59
|
+
assert File.exists?(out_filename)
|
60
|
+
i2 = QuickMagick::Image.read(out_filename).first
|
61
|
+
assert_equal 300, i2.width
|
62
|
+
assert_equal 300, i2.height
|
63
|
+
ensure
|
64
|
+
# clean up
|
65
|
+
File.delete(out_filename) if out_filename && File.exists?(out_filename)
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_crop_image
|
69
|
+
image_filename = File.join($base_dir, "imagemagick-logo.png")
|
70
|
+
i = QuickMagick::Image.read(image_filename).first
|
71
|
+
i.crop("300x200+0+0")
|
72
|
+
out_filename = File.join($base_dir, "imagemagick-cropped.png")
|
73
|
+
File.delete out_filename if File.exists?(out_filename)
|
74
|
+
i.save(out_filename)
|
75
|
+
assert File.exists?(out_filename)
|
76
|
+
i2 = QuickMagick::Image.read(out_filename).first
|
77
|
+
assert_equal 300, i2.width
|
78
|
+
assert_equal 200, i2.height
|
79
|
+
ensure
|
80
|
+
# clean up
|
81
|
+
File.delete(out_filename) if out_filename && File.exists?(out_filename)
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_resize_with_geometry_options
|
85
|
+
image_filename = File.join($base_dir, "imagemagick-logo.png")
|
86
|
+
i = QuickMagick::Image.read(image_filename).first
|
87
|
+
i.resize(300, 300, nil, nil, QuickMagick::AspectGeometry)
|
88
|
+
out_filename = File.join($base_dir, "imagemagick-resized.png")
|
89
|
+
File.delete out_filename if File.exists?(out_filename)
|
90
|
+
i.save(out_filename)
|
91
|
+
assert File.exists?(out_filename)
|
92
|
+
i2 = QuickMagick::Image.read(out_filename).first
|
93
|
+
assert_equal 300, i2.width
|
94
|
+
assert_equal 300, i2.height
|
95
|
+
ensure
|
96
|
+
# clean up
|
97
|
+
File.delete(out_filename) if out_filename && File.exists?(out_filename)
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_resize_with_append_to_operators
|
101
|
+
image_filename = File.join($base_dir, "imagemagick-logo.png")
|
102
|
+
i = QuickMagick::Image.read(image_filename).first
|
103
|
+
i.append_to_operators 'resize', '300x300!'
|
104
|
+
out_filename = File.join($base_dir, "imagemagick-resized.png")
|
105
|
+
File.delete out_filename if File.exists?(out_filename)
|
106
|
+
i.save(out_filename)
|
107
|
+
assert File.exists?(out_filename)
|
108
|
+
i2 = QuickMagick::Image.read(out_filename).first
|
109
|
+
assert_equal 300, i2.width
|
110
|
+
assert_equal 300, i2.height
|
111
|
+
ensure
|
112
|
+
# clean up
|
113
|
+
File.delete(out_filename) if out_filename && File.exists?(out_filename)
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_create_solid_image
|
117
|
+
i = QuickMagick::Image.solid(100, 100, :white)
|
118
|
+
assert_equal 100, i.width
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_create_gradient_image
|
122
|
+
i = QuickMagick::Image.gradient(100, 100, QuickMagick::RadialGradient, :yellow, :blue)
|
123
|
+
assert_equal 100, i.width
|
124
|
+
end
|
125
|
+
end
|
Binary file
|
data/test/logo-small.jpg
ADDED
Binary file
|
data/test/multipage.tif
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: quick_magick
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ahmed ElDawy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-07-29 00:00:00 +03: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/logo-small.jpg
|
37
|
+
- test/badfile.xxx
|
38
|
+
- test/multipage.tif
|
39
|
+
- test/image_list_test.rb
|
40
|
+
- test/imagemagick-logo.png
|
41
|
+
has_rdoc: true
|
42
|
+
homepage: http://quickmagick.rubyforge.org/
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options:
|
45
|
+
- --line-numbers
|
46
|
+
- --inline-source
|
47
|
+
- --title
|
48
|
+
- Quick_magick
|
49
|
+
- --main
|
50
|
+
- README
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
version:
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "1.2"
|
64
|
+
version:
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project: quickmagick
|
68
|
+
rubygems_version: 1.3.1
|
69
|
+
signing_key:
|
70
|
+
specification_version: 2
|
71
|
+
summary: QuickMagick allows you to access ImageMagick command line functions using Ruby interface.
|
72
|
+
test_files:
|
73
|
+
- test/image_test.rb
|
74
|
+
- test/image_list_test.rb
|