mini_magick 3.3 → 3.4
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of mini_magick might be problematic. Click here for more details.
- data/README.rdoc +20 -1
- data/Rakefile +10 -24
- data/VERSION +1 -1
- data/lib/mini_magick.rb +58 -19
- data/test/command_builder_test.rb +7 -3
- data/test/{actually_a_gif.jpg → files/actually_a_gif.jpg} +0 -0
- data/test/{animation.gif → files/animation.gif} +0 -0
- data/test/{composited.jpg → files/composited.jpg} +0 -0
- data/test/files/leaves (spaced).tiff +0 -0
- data/test/{not_an_image.php → files/not_an_image.php} +0 -0
- data/test/{png.png → files/png.png} +0 -0
- data/test/{simple-minus.gif → files/simple-minus.gif} +0 -0
- data/test/{simple.gif → files/simple.gif} +0 -0
- data/test/{trogdor.jpg → files/trogdor.jpg} +0 -0
- data/test/files/trogdor_capitalized.JPG +0 -0
- data/test/image_test.rb +32 -34
- data/test/test_helper.rb +20 -0
- metadata +73 -54
data/README.rdoc
CHANGED
@@ -64,7 +64,7 @@ Need to combine several options?
|
|
64
64
|
|
65
65
|
Want to composite two images? Super easy! (Aka, put a watermark on!)
|
66
66
|
|
67
|
-
image = Image.
|
67
|
+
image = Image.open("original.png")
|
68
68
|
result = image.composite(Image.open("watermark.png", "jpg") do |c|
|
69
69
|
c.gravity "center"
|
70
70
|
end
|
@@ -83,10 +83,29 @@ Want to get some meta-information out?
|
|
83
83
|
image["EXIF:BitsPerSample"] # It also can get all the EXIF tags
|
84
84
|
image["%m:%f %wx%h"] # Or you can use one of the many options of the format command
|
85
85
|
|
86
|
+
Want to use an internal image creation to create a big black square?
|
87
|
+
|
88
|
+
image = MiniMagick::Image.create 'jpg', false do |c|
|
89
|
+
c.size '1024x1024' # creates image option '-size 1024x1024'
|
90
|
+
c.canvas 'black' # creates image creation operator 'canvas:black'
|
91
|
+
end
|
92
|
+
|
86
93
|
For more on the format command see
|
87
94
|
http://www.imagemagick.org/script/command-line-options.php#format
|
88
95
|
|
89
96
|
|
97
|
+
== Windows Users
|
98
|
+
|
99
|
+
When passing in a blob or IOStream, Windows users need to make sure they read the file in as binary.
|
100
|
+
|
101
|
+
#This way works on Windows
|
102
|
+
buffer = StringIO.new(File.open(IMAGE_PATH,"rb") { |f| f.read })
|
103
|
+
MiniMagick::Image.read(buffer)
|
104
|
+
|
105
|
+
#You may run into problems doing it this way
|
106
|
+
buffer = StringIO.new(File.read(IMAGE_PATH))
|
107
|
+
|
108
|
+
|
90
109
|
== Using GraphicsMagick
|
91
110
|
|
92
111
|
Simply set
|
data/Rakefile
CHANGED
@@ -1,34 +1,20 @@
|
|
1
|
-
require '
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
2
4
|
require 'rake/testtask'
|
3
|
-
require 'rdoc/task'
|
4
|
-
require 'rubygems/package_task'
|
5
5
|
|
6
|
-
$:.unshift
|
7
|
-
require 'mini_magick'
|
6
|
+
$:.unshift 'lib'
|
8
7
|
|
9
8
|
desc 'Default: run unit tests.'
|
10
|
-
task :default => :test
|
9
|
+
task :default => [:print_version, :test]
|
10
|
+
|
11
|
+
task :print_version do
|
12
|
+
puts `mogrify --version`
|
13
|
+
end
|
11
14
|
|
12
15
|
desc 'Test the mini_magick plugin.'
|
13
16
|
Rake::TestTask.new(:test) do |t|
|
14
17
|
t.libs << 'test'
|
15
|
-
t.
|
18
|
+
t.test_files = Dir.glob("test/**/*_test.rb")
|
16
19
|
t.verbose = true
|
17
20
|
end
|
18
|
-
|
19
|
-
desc 'Generate documentation for the mini_magick plugin.'
|
20
|
-
Rake::RDocTask.new(:rdoc) do |rdoc|
|
21
|
-
rdoc.rdoc_dir = 'rdoc'
|
22
|
-
rdoc.title = 'MiniMagick'
|
23
|
-
rdoc.options << '--line-numbers'
|
24
|
-
rdoc.options << '--inline-source'
|
25
|
-
rdoc.rdoc_files.include('README.rdoc')
|
26
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
27
|
-
end
|
28
|
-
|
29
|
-
spec = eval(File.read('mini_magick.gemspec'))
|
30
|
-
Gem::PackageTask.new(spec) do |pkg|
|
31
|
-
pkg.gem_spec = spec
|
32
|
-
pkg.need_zip = true
|
33
|
-
pkg.need_tar = true
|
34
|
-
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.4
|
data/lib/mini_magick.rb
CHANGED
@@ -20,9 +20,23 @@ module MiniMagick
|
|
20
20
|
self.processor = "gm"
|
21
21
|
end
|
22
22
|
end
|
23
|
+
|
24
|
+
def image_magick_version
|
25
|
+
@@version ||= Gem::Version.create(`mogrify --version`.split(" ")[2].split("-").first)
|
26
|
+
end
|
27
|
+
|
28
|
+
def minimum_image_magick_version
|
29
|
+
@@minimum_version ||= Gem::Version.create("6.6.3")
|
30
|
+
end
|
31
|
+
|
32
|
+
def valid_version_installed?
|
33
|
+
image_magick_version >= minimum_image_magick_version
|
34
|
+
end
|
23
35
|
end
|
24
36
|
|
25
|
-
MOGRIFY_COMMANDS = %w{adaptive-blur adaptive-resize adaptive-sharpen adjoin affine alpha annotate antialias append authenticate auto-gamma auto-level auto-orient background bench iterations bias black-threshold blue-primary point blue-shift factor blur border bordercolor brightness-contrast caption string cdl filename channel type charcoal radius chop clip clamp clip-mask filename clip-path id clone index clut contrast-stretch coalesce colorize color-matrix colors colorspace type combine comment string compose operator composite compress type contrast convolve coefficients crop cycle amount decipher filename debug events define format:option deconstruct delay delete index density depth despeckle direction type display server dispose method distort type coefficients dither method draw string edge radius emboss radius encipher filename encoding type endian type enhance equalize evaluate operator evaluate-sequence operator extent extract family name fft fill filter type flatten flip floodfill flop font name format string frame function name fuzz distance fx expression gamma gaussian-blur geometry gravity type green-primary point help identify ifft implode amount insert index intent type interlace type interline-spacing interpolate method interword-spacing kerning label string lat layers method level limit type linear-stretch liquid-rescale log format loop iterations mask filename mattecolor median radius modulate monitor monochrome morph morphology method kernel motion-blur negate noise radius normalize opaque ordered-dither NxN orient type page paint radius ping pointsize polaroid angle posterize levels precision preview type print string process image-filter profile filename quality quantize quiet radial-blur angle raise random-threshold low,high red-primary point regard-warnings region remap filename render repage resample resize respect-parentheses roll rotate degrees sample sampling-factor scale scene seed segments selective-blur separate sepia-tone threshold set attribute shade degrees shadow sharpen shave shear sigmoidal-contrast size sketch solarize threshold splice spread radius strip stroke strokewidth stretch type style type swap indexes swirl degrees texture filename threshold thumbnail tile filename tile-offset tint transform transparent transparent-color transpose transverse treedepth trim type type undercolor unique-colors units type unsharp verbose version view vignette virtual-pixel method wave weight type white-point point white-threshold write filename}
|
37
|
+
MOGRIFY_COMMANDS = %w{adaptive-blur adaptive-resize adaptive-sharpen adjoin affine alpha annotate antialias append authenticate auto-gamma auto-level auto-orient background bench iterations bias black-threshold blue-primary point blue-shift factor blur border bordercolor brightness-contrast caption string cdl filename channel type charcoal radius chop clip clamp clip-mask filename clip-path id clone index clut contrast-stretch coalesce colorize color-matrix colors colorspace type combine comment string compose operator composite compress type contrast convolve coefficients crop cycle amount decipher filename debug events define format:option deconstruct delay delete index density depth despeckle direction type dissolve display server dispose method distort type coefficients dither method draw string edge radius emboss radius encipher filename encoding type endian type enhance equalize evaluate operator evaluate-sequence operator extent extract family name fft fill filter type flatten flip floodfill flop font name format string frame function name fuzz distance fx expression gamma gaussian-blur geometry gravity type green-primary point help identify ifft implode amount insert index intent type interlace type interline-spacing interpolate method interword-spacing kerning label string lat layers method level limit type linear-stretch liquid-rescale log format loop iterations mask filename mattecolor median radius modulate monitor monochrome morph morphology method kernel motion-blur negate noise radius normalize opaque ordered-dither NxN orient type page paint radius ping pointsize polaroid angle posterize levels precision preview type print string process image-filter profile filename quality quantize quiet radial-blur angle raise random-threshold low,high red-primary point regard-warnings region remap filename render repage resample resize respect-parentheses roll rotate degrees sample sampling-factor scale scene seed segments selective-blur separate sepia-tone threshold set attribute shade degrees shadow sharpen shave shear sigmoidal-contrast size sketch solarize threshold splice spread radius strip stroke strokewidth stretch type style type swap indexes swirl degrees texture filename threshold thumbnail tile filename tile-offset tint transform transparent transparent-color transpose transverse treedepth trim type type undercolor unique-colors units type unsharp verbose version view vignette virtual-pixel method wave weight type white-point point white-threshold write filename}
|
38
|
+
|
39
|
+
IMAGE_CREATION_OPERATORS = %w{canvas caption gradient label logo pattern plasma radial radient rose text tile xc }
|
26
40
|
|
27
41
|
class Error < RuntimeError; end
|
28
42
|
class Invalid < StandardError; end
|
@@ -48,6 +62,12 @@ module MiniMagick
|
|
48
62
|
def read(stream, ext = nil)
|
49
63
|
if stream.is_a?(String)
|
50
64
|
stream = StringIO.new(stream)
|
65
|
+
elsif stream.is_a?(File)
|
66
|
+
if File.respond_to?(:binread)
|
67
|
+
stream = StringIO.new File.binread(stream.path.to_s)
|
68
|
+
else
|
69
|
+
stream = StringIO.new File.open(stream.path.to_s,"rb") { |f| f.read }
|
70
|
+
end
|
51
71
|
end
|
52
72
|
|
53
73
|
create(ext) do |f|
|
@@ -201,29 +221,29 @@ module MiniMagick
|
|
201
221
|
# Why do I go to the trouble of putting in newlines? Because otherwise animated gifs screw everything up
|
202
222
|
case value.to_s
|
203
223
|
when "colorspace"
|
204
|
-
run_command("identify", "-format", format_option("%r"), escaped_path).split("\n")[0]
|
224
|
+
run_command("identify", "-quiet", "-format", format_option("%r"), escaped_path).split("\n")[0]
|
205
225
|
when "format"
|
206
|
-
run_command("identify", "-format", format_option("%m"), escaped_path).split("\n")[0]
|
226
|
+
run_command("identify", "-quiet", "-format", format_option("%m"), escaped_path).split("\n")[0]
|
207
227
|
when "height"
|
208
|
-
run_command("identify", "-format", format_option("%h"), escaped_path).split("\n")[0].to_i
|
228
|
+
run_command("identify", "-quiet", "-format", format_option("%h"), escaped_path).split("\n")[0].to_i
|
209
229
|
when "width"
|
210
|
-
run_command("identify", "-format", format_option("%w"), escaped_path).split("\n")[0].to_i
|
230
|
+
run_command("identify", "-quiet", "-format", format_option("%w"), escaped_path).split("\n")[0].to_i
|
211
231
|
when "dimensions"
|
212
|
-
run_command("identify", "-format", format_option("%w %h"), escaped_path).split("\n")[0].split.map{|v|v.to_i}
|
232
|
+
run_command("identify", "-quiet", "-format", format_option("%w %h"), escaped_path).split("\n")[0].split.map{|v|v.to_i}
|
213
233
|
when "size"
|
214
234
|
File.size(@path) # Do this because calling identify -format "%b" on an animated gif fails!
|
215
235
|
when "original_at"
|
216
236
|
# Get the EXIF original capture as a Time object
|
217
237
|
Time.local(*self["EXIF:DateTimeOriginal"].split(/:|\s+/)) rescue nil
|
218
238
|
when /^EXIF\:/i
|
219
|
-
result = run_command('identify', '-format', "\"%[#{value}]\"", escaped_path).chop
|
239
|
+
result = run_command('identify', '-quiet', '-format', "\"%[#{value}]\"", escaped_path).chop
|
220
240
|
if result.include?(",")
|
221
241
|
read_character_data(result)
|
222
242
|
else
|
223
243
|
result
|
224
244
|
end
|
225
245
|
else
|
226
|
-
run_command('identify', '-format', "\"#{value}\"", escaped_path).split("\n")[0]
|
246
|
+
run_command('identify', '-quiet', '-format', "\"#{value}\"", escaped_path).split("\n")[0]
|
227
247
|
end
|
228
248
|
end
|
229
249
|
|
@@ -309,13 +329,13 @@ module MiniMagick
|
|
309
329
|
ensure
|
310
330
|
f.close if f
|
311
331
|
end
|
312
|
-
|
332
|
+
|
313
333
|
def mime_type
|
314
334
|
format = self[:format]
|
315
|
-
"image/"+format.downcase
|
335
|
+
"image/" + format.to_s.downcase
|
316
336
|
end
|
317
337
|
|
318
|
-
# If an unknown method is called then it is sent through the
|
338
|
+
# If an unknown method is called then it is sent through the mogrify program
|
319
339
|
# Look here to find all the commands (http://www.imagemagick.org/script/mogrify.php)
|
320
340
|
def method_missing(symbol, *args)
|
321
341
|
combine_options do |c|
|
@@ -333,8 +353,10 @@ module MiniMagick
|
|
333
353
|
# end
|
334
354
|
#
|
335
355
|
# @yieldparam command [CommandBuilder]
|
336
|
-
def combine_options(&block)
|
337
|
-
c = CommandBuilder.new(
|
356
|
+
def combine_options(tool = :mogrify, &block)
|
357
|
+
c = CommandBuilder.new(tool)
|
358
|
+
|
359
|
+
c << @path if tool == :convert
|
338
360
|
block.call(c)
|
339
361
|
c << @path
|
340
362
|
run(c)
|
@@ -342,7 +364,7 @@ module MiniMagick
|
|
342
364
|
|
343
365
|
# Check to see if we are running on win32 -- we need to escape things differently
|
344
366
|
def windows?
|
345
|
-
|
367
|
+
RUBY_PLATFORM =~ /mswin|mingw|cygwin/
|
346
368
|
end
|
347
369
|
|
348
370
|
def composite(other_image, output_extension = 'jpg', &block)
|
@@ -401,7 +423,7 @@ module MiniMagick
|
|
401
423
|
|
402
424
|
def destroy!
|
403
425
|
return if @tempfile.nil?
|
404
|
-
File.unlink(@tempfile.path)
|
426
|
+
File.unlink(@tempfile.path) if File.exists?(@tempfile.path)
|
405
427
|
@tempfile = nil
|
406
428
|
end
|
407
429
|
|
@@ -436,7 +458,10 @@ module MiniMagick
|
|
436
458
|
if guessed_command_name == "format"
|
437
459
|
raise Error, "You must call 'format' on the image object directly!"
|
438
460
|
elsif MOGRIFY_COMMANDS.include?(guessed_command_name)
|
439
|
-
|
461
|
+
add_command(guessed_command_name, *options)
|
462
|
+
self
|
463
|
+
elsif IMAGE_CREATION_OPERATORS.include?(guessed_command_name)
|
464
|
+
add_creation_operator(guessed_command_name, *options)
|
440
465
|
self
|
441
466
|
else
|
442
467
|
super(symbol, *args)
|
@@ -447,18 +472,32 @@ module MiniMagick
|
|
447
472
|
push(@args.pop.gsub(/^-/, '+'))
|
448
473
|
if options.any?
|
449
474
|
options.each do |o|
|
450
|
-
push
|
475
|
+
push escape_string(o)
|
451
476
|
end
|
452
477
|
end
|
453
478
|
end
|
454
479
|
|
455
|
-
def
|
480
|
+
def add_command(command, *options)
|
456
481
|
push "-#{command}"
|
457
482
|
if options.any?
|
458
483
|
options.each do |o|
|
459
|
-
push
|
484
|
+
push escape_string(o)
|
485
|
+
end
|
486
|
+
end
|
487
|
+
end
|
488
|
+
|
489
|
+
def escape_string(value)
|
490
|
+
'"' + value + '"'
|
491
|
+
end
|
492
|
+
|
493
|
+
def add_creation_operator(command, *options)
|
494
|
+
creation_command = command
|
495
|
+
if options.any?
|
496
|
+
options.each do |option|
|
497
|
+
creation_command << ":#{option}"
|
460
498
|
end
|
461
499
|
end
|
500
|
+
push creation_command
|
462
501
|
end
|
463
502
|
|
464
503
|
def push(arg)
|
@@ -1,6 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
require 'test/unit'
|
3
|
-
require File.expand_path('../../lib/mini_magick', __FILE__)
|
1
|
+
require 'test_helper'
|
4
2
|
|
5
3
|
class CommandBuilderTest < Test::Unit::TestCase
|
6
4
|
include MiniMagick
|
@@ -40,4 +38,10 @@ class CommandBuilderTest < Test::Unit::TestCase
|
|
40
38
|
c.auto_orient
|
41
39
|
assert_equal "-auto-orient", c.args.join(" ")
|
42
40
|
end
|
41
|
+
|
42
|
+
def test_canvas
|
43
|
+
c = CommandBuilder.new('test')
|
44
|
+
c.canvas 'black'
|
45
|
+
assert_equal "canvas:black", c.args.join
|
46
|
+
end
|
43
47
|
end
|
File without changes
|
File without changes
|
File without changes
|
Binary file
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
Binary file
|
data/test/image_test.rb
CHANGED
@@ -1,24 +1,10 @@
|
|
1
|
-
require '
|
2
|
-
require 'test/unit'
|
3
|
-
require 'pathname'
|
4
|
-
require File.expand_path('../../lib/mini_magick', __FILE__)
|
1
|
+
require 'test_helper'
|
5
2
|
|
6
3
|
#MiniMagick.processor = :gm
|
7
4
|
|
8
5
|
class ImageTest < Test::Unit::TestCase
|
9
6
|
include MiniMagick
|
10
|
-
|
11
|
-
CURRENT_DIR = File.dirname(File.expand_path(__FILE__)) + "/"
|
12
|
-
|
13
|
-
SIMPLE_IMAGE_PATH = CURRENT_DIR + "simple.gif"
|
14
|
-
MINUS_IMAGE_PATH = CURRENT_DIR + "simple-minus.gif"
|
15
|
-
TIFF_IMAGE_PATH = CURRENT_DIR + "leaves (spaced).tiff"
|
16
|
-
NOT_AN_IMAGE_PATH = CURRENT_DIR + "not_an_image.php"
|
17
|
-
GIF_WITH_JPG_EXT = CURRENT_DIR + "actually_a_gif.jpg"
|
18
|
-
EXIF_IMAGE_PATH = CURRENT_DIR + "trogdor.jpg"
|
19
|
-
CAP_EXT_PATH = CURRENT_DIR + "trogdor_capitalized.JPG"
|
20
|
-
ANIMATION_PATH = CURRENT_DIR + "animation.gif"
|
21
|
-
PNG_PATH = CURRENT_DIR + "png.png"
|
7
|
+
include MiniMagickTestFiles
|
22
8
|
|
23
9
|
def test_image_from_blob
|
24
10
|
File.open(SIMPLE_IMAGE_PATH, "rb") do |f|
|
@@ -35,7 +21,8 @@ class ImageTest < Test::Unit::TestCase
|
|
35
21
|
end
|
36
22
|
|
37
23
|
def test_image_io_reading
|
38
|
-
buffer = StringIO.new(File.read(SIMPLE_IMAGE_PATH))
|
24
|
+
# buffer = StringIO.new(File.read(SIMPLE_IMAGE_PATH)) #This way does not work properly on windows
|
25
|
+
buffer = StringIO.new File.open(SIMPLE_IMAGE_PATH,"rb") { |f| f.read } #This way works the same on all platforms
|
39
26
|
image = Image.read(buffer)
|
40
27
|
assert image.valid?
|
41
28
|
image.destroy!
|
@@ -43,7 +30,8 @@ class ImageTest < Test::Unit::TestCase
|
|
43
30
|
|
44
31
|
def test_image_create
|
45
32
|
image = Image.create do |f|
|
46
|
-
|
33
|
+
#Had to replace the old File.read with the following to work across all platforms
|
34
|
+
f.write(File.open(SIMPLE_IMAGE_PATH,"rb") { |f| f.read })
|
47
35
|
end
|
48
36
|
image.destroy!
|
49
37
|
end
|
@@ -54,7 +42,7 @@ class ImageTest < Test::Unit::TestCase
|
|
54
42
|
end
|
55
43
|
|
56
44
|
def test_remote_image
|
57
|
-
image = Image.open("http://
|
45
|
+
image = Image.open("http://upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png")
|
58
46
|
assert image.valid?
|
59
47
|
image.destroy!
|
60
48
|
end
|
@@ -99,7 +87,7 @@ class ImageTest < Test::Unit::TestCase
|
|
99
87
|
def test_image_write_with_stream
|
100
88
|
stream = StringIO.new
|
101
89
|
image = Image.open(SIMPLE_IMAGE_PATH)
|
102
|
-
image.write("/
|
90
|
+
image.write("#{Dir.tmpdir}/foo.gif")
|
103
91
|
image.write(stream)
|
104
92
|
# assert Image.read(stream.string).valid?
|
105
93
|
image.destroy!
|
@@ -111,7 +99,7 @@ class ImageTest < Test::Unit::TestCase
|
|
111
99
|
image.destroy!
|
112
100
|
end
|
113
101
|
|
114
|
-
def
|
102
|
+
def test_throw_on_opening_not_an_image
|
115
103
|
assert_raise(MiniMagick::Invalid) do
|
116
104
|
image = Image.open(NOT_AN_IMAGE_PATH)
|
117
105
|
image.destroy
|
@@ -130,7 +118,7 @@ class ImageTest < Test::Unit::TestCase
|
|
130
118
|
|
131
119
|
def test_tiff
|
132
120
|
image = Image.new(TIFF_IMAGE_PATH)
|
133
|
-
assert_equal "tiff", image[:format].downcase
|
121
|
+
assert_equal "tiff", image[:format].to_s.downcase
|
134
122
|
assert_equal 50, image[:width]
|
135
123
|
assert_equal 41, image[:height]
|
136
124
|
image.destroy!
|
@@ -138,7 +126,7 @@ class ImageTest < Test::Unit::TestCase
|
|
138
126
|
|
139
127
|
def test_gif_with_jpg_format
|
140
128
|
image = Image.new(GIF_WITH_JPG_EXT)
|
141
|
-
assert_equal "gif", image[:format].downcase
|
129
|
+
assert_equal "gif", image[:format].to_s.downcase
|
142
130
|
image.destroy!
|
143
131
|
end
|
144
132
|
|
@@ -213,7 +201,7 @@ class ImageTest < Test::Unit::TestCase
|
|
213
201
|
def test_tempfile_at_path_after_format
|
214
202
|
image = Image.open(TIFF_IMAGE_PATH)
|
215
203
|
image.format('png')
|
216
|
-
|
204
|
+
assert File.exists?(image.path)
|
217
205
|
image.destroy!
|
218
206
|
end
|
219
207
|
|
@@ -238,11 +226,21 @@ class ImageTest < Test::Unit::TestCase
|
|
238
226
|
end
|
239
227
|
|
240
228
|
def test_simple_composite
|
241
|
-
|
242
|
-
|
243
|
-
|
229
|
+
if MiniMagick.valid_version_installed?
|
230
|
+
image = Image.open(EXIF_IMAGE_PATH)
|
231
|
+
result = image.composite(Image.open(TIFF_IMAGE_PATH)) do |c|
|
232
|
+
c.gravity "center"
|
233
|
+
end
|
234
|
+
assert `diff -s #{result.path} test/files/composited.jpg`.include?("identical")
|
235
|
+
else
|
236
|
+
puts "Need at least version #{MiniMagick.minimum_image_magick_version} of ImageMagick"
|
244
237
|
end
|
245
|
-
|
238
|
+
#TODO - need to write test that works cross platform
|
239
|
+
#I thought the following would work but there is a 4 byte difference between the files.
|
240
|
+
#Not sure if it's caused from this test breaking for the right reason though..
|
241
|
+
#assert File.identical?(result.path, COMP_IMAGE_PATH)
|
242
|
+
#This following test will only work on Linux
|
243
|
+
assert `diff -s #{result.path} #{COMP_IMAGE_PATH}`.include?("identical") unless RUBY_PLATFORM =~ /mswin|mingw|cygwin/
|
246
244
|
end
|
247
245
|
|
248
246
|
# http://github.com/probablycorey/mini_magick/issues#issue/8
|
@@ -272,7 +270,7 @@ class ImageTest < Test::Unit::TestCase
|
|
272
270
|
ENV["LANG"] = "fr_FR.UTF-8"
|
273
271
|
|
274
272
|
# This test should break
|
275
|
-
|
273
|
+
test_throw_on_opening_not_an_image
|
276
274
|
ensure
|
277
275
|
ENV["LANG"] = original_lang
|
278
276
|
end
|
@@ -282,7 +280,7 @@ class ImageTest < Test::Unit::TestCase
|
|
282
280
|
img.gravity "Center"
|
283
281
|
img.crop "480x480"
|
284
282
|
img.resize "250x250"
|
285
|
-
img.write "/
|
283
|
+
img.write "#{Dir.tmpdir}/output.png"
|
286
284
|
end
|
287
285
|
|
288
286
|
def test_throw_format_error
|
@@ -304,10 +302,10 @@ class ImageTest < Test::Unit::TestCase
|
|
304
302
|
blob = pixels.pack("S*") # unsigned short, native byte order
|
305
303
|
image = Image.import_pixels(blob, columns, rows, depth, map)
|
306
304
|
assert image.valid?
|
307
|
-
assert_equal "png", image[:format].downcase
|
305
|
+
assert_equal "png", image[:format].to_s.downcase
|
308
306
|
assert_equal columns, image[:width]
|
309
307
|
assert_equal rows, image[:height]
|
310
|
-
image.write("/
|
308
|
+
image.write("#{Dir.tmpdir}/imported_pixels_image.png")
|
311
309
|
end
|
312
310
|
|
313
311
|
def test_import_pixels_custom_format
|
@@ -320,10 +318,10 @@ class ImageTest < Test::Unit::TestCase
|
|
320
318
|
blob = pixels.pack("S*") # unsigned short, native byte order
|
321
319
|
image = Image.import_pixels(blob, columns, rows, depth, map, format)
|
322
320
|
assert image.valid?
|
323
|
-
assert_equal format, image[:format].downcase
|
321
|
+
assert_equal format, image[:format].to_s.downcase
|
324
322
|
assert_equal columns, image[:width]
|
325
323
|
assert_equal rows, image[:height]
|
326
|
-
image.write("/
|
324
|
+
image.write("#{Dir.tmpdir}/imported_pixels_image." + format)
|
327
325
|
end
|
328
326
|
|
329
327
|
def test_mime_type
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'pathname'
|
4
|
+
require 'tempfile'
|
5
|
+
require File.expand_path('../../lib/mini_magick', __FILE__)
|
6
|
+
|
7
|
+
|
8
|
+
module MiniMagickTestFiles
|
9
|
+
test_files = File.expand_path(File.dirname(__FILE__) + "/files")
|
10
|
+
SIMPLE_IMAGE_PATH = test_files + "/simple.gif"
|
11
|
+
MINUS_IMAGE_PATH = test_files + "/simple-minus.gif"
|
12
|
+
TIFF_IMAGE_PATH = test_files + "/leaves (spaced).tiff"
|
13
|
+
NOT_AN_IMAGE_PATH = test_files + "/not_an_image.php"
|
14
|
+
GIF_WITH_JPG_EXT = test_files + "/actually_a_gif.jpg"
|
15
|
+
EXIF_IMAGE_PATH = test_files + "/trogdor.jpg"
|
16
|
+
CAP_EXT_PATH = test_files + "/trogdor_capitalized.JPG"
|
17
|
+
ANIMATION_PATH = test_files + "/animation.gif"
|
18
|
+
PNG_PATH = test_files + "/png.png"
|
19
|
+
COMP_IMAGE_PATH = test_files + "/composited.jpg"
|
20
|
+
end
|
metadata
CHANGED
@@ -1,99 +1,118 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: mini_magick
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '3.4'
|
4
5
|
prerelease:
|
5
|
-
version: "3.3"
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Corey Johnson
|
9
9
|
- Hampton Catlin
|
10
10
|
- Peter Kieltyka
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
dependencies:
|
18
|
-
- !ruby/object:Gem::Dependency
|
14
|
+
date: 2011-12-28 00:00:00.000000000Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
19
17
|
name: subexec
|
20
|
-
|
21
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
requirement: &70171864234000 !ruby/object:Gem::Requirement
|
22
19
|
none: false
|
23
|
-
requirements:
|
20
|
+
requirements:
|
24
21
|
- - ~>
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 0.1
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.2.1
|
27
24
|
type: :runtime
|
28
|
-
|
29
|
-
|
30
|
-
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *70171864234000
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: &70171864233600 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *70171864233600
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: test-unit
|
40
|
+
requirement: &70171864233140 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
type: :development
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *70171864233140
|
49
|
+
description: ''
|
50
|
+
email:
|
31
51
|
- probablycorey@gmail.com
|
32
52
|
- hcatlin@gmail.com
|
33
53
|
- peter@nulayer.com
|
34
54
|
executables: []
|
35
|
-
|
36
55
|
extensions: []
|
37
|
-
|
38
56
|
extra_rdoc_files: []
|
39
|
-
|
40
|
-
files:
|
57
|
+
files:
|
41
58
|
- README.rdoc
|
42
59
|
- VERSION
|
43
60
|
- MIT-LICENSE
|
44
61
|
- Rakefile
|
45
62
|
- lib/mini_gmagick.rb
|
46
63
|
- lib/mini_magick.rb
|
47
|
-
- test/actually_a_gif.jpg
|
48
|
-
- test/animation.gif
|
49
64
|
- test/command_builder_test.rb
|
50
|
-
- test/
|
65
|
+
- test/files/actually_a_gif.jpg
|
66
|
+
- test/files/animation.gif
|
67
|
+
- test/files/composited.jpg
|
68
|
+
- test/files/leaves (spaced).tiff
|
69
|
+
- test/files/not_an_image.php
|
70
|
+
- test/files/png.png
|
71
|
+
- test/files/simple-minus.gif
|
72
|
+
- test/files/simple.gif
|
73
|
+
- test/files/trogdor.jpg
|
74
|
+
- test/files/trogdor_capitalized.JPG
|
51
75
|
- test/image_test.rb
|
52
76
|
- test/leaves (spaced).tiff
|
53
|
-
- test/
|
54
|
-
- test/png.png
|
55
|
-
- test/simple-minus.gif
|
56
|
-
- test/simple.gif
|
57
|
-
- test/trogdor.jpg
|
77
|
+
- test/test_helper.rb
|
58
78
|
- test/trogdor_capitalized.JPG
|
59
|
-
has_rdoc: true
|
60
79
|
homepage: http://github.com/probablycorey/mini_magick
|
61
80
|
licenses: []
|
62
|
-
|
63
81
|
post_install_message:
|
64
82
|
rdoc_options: []
|
65
|
-
|
66
|
-
require_paths:
|
83
|
+
require_paths:
|
67
84
|
- lib
|
68
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
86
|
none: false
|
70
|
-
requirements:
|
71
|
-
- -
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
version:
|
74
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
92
|
none: false
|
76
|
-
requirements:
|
77
|
-
- -
|
78
|
-
- !ruby/object:Gem::Version
|
79
|
-
version:
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
80
97
|
requirements: []
|
81
|
-
|
82
98
|
rubyforge_project:
|
83
|
-
rubygems_version: 1.6
|
99
|
+
rubygems_version: 1.8.6
|
84
100
|
signing_key:
|
85
101
|
specification_version: 3
|
86
102
|
summary: Manipulate images with minimal use of memory via ImageMagick / GraphicsMagick
|
87
|
-
test_files:
|
88
|
-
- test/actually_a_gif.jpg
|
89
|
-
- test/animation.gif
|
103
|
+
test_files:
|
90
104
|
- test/command_builder_test.rb
|
91
|
-
- test/
|
105
|
+
- test/files/actually_a_gif.jpg
|
106
|
+
- test/files/animation.gif
|
107
|
+
- test/files/composited.jpg
|
108
|
+
- test/files/leaves (spaced).tiff
|
109
|
+
- test/files/not_an_image.php
|
110
|
+
- test/files/png.png
|
111
|
+
- test/files/simple-minus.gif
|
112
|
+
- test/files/simple.gif
|
113
|
+
- test/files/trogdor.jpg
|
114
|
+
- test/files/trogdor_capitalized.JPG
|
92
115
|
- test/image_test.rb
|
93
116
|
- test/leaves (spaced).tiff
|
94
|
-
- test/
|
95
|
-
- test/png.png
|
96
|
-
- test/simple-minus.gif
|
97
|
-
- test/simple.gif
|
98
|
-
- test/trogdor.jpg
|
117
|
+
- test/test_helper.rb
|
99
118
|
- test/trogdor_capitalized.JPG
|