mini_magick 3.5.0 → 3.6.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 mini_magick might be problematic. Click here for more details.
- data/lib/mini_magick.rb +36 -47
- data/lib/mini_magick/version.rb +1 -1
- data/test/command_builder_test.rb +25 -1
- data/test/files/special! /"chars'.gif +0 -0
- data/test/image_test.rb +27 -0
- data/test/test_helper.rb +12 -11
- metadata +7 -3
data/lib/mini_magick.rb
CHANGED
@@ -7,6 +7,7 @@ require 'shellwords'
|
|
7
7
|
module MiniMagick
|
8
8
|
class << self
|
9
9
|
attr_accessor :processor
|
10
|
+
attr_accessor :processor_path
|
10
11
|
attr_accessor :timeout
|
11
12
|
|
12
13
|
|
@@ -106,8 +107,8 @@ module MiniMagick
|
|
106
107
|
image = create(".dat", validate = false) { |f| f.write(blob) }
|
107
108
|
# Use ImageMagick to convert the raw data file to an image file of the desired format:
|
108
109
|
converted_image_path = image.path[0..-4] + format
|
109
|
-
|
110
|
-
cmd = CommandBuilder.new("convert",
|
110
|
+
arguments = ["-size", "#{columns}x#{rows}", "-depth", "#{depth}", "#{map}:#{image.path}", "#{converted_image_path}"]
|
111
|
+
cmd = CommandBuilder.new("convert", *arguments) #Example: convert -size 256x256 -depth 16 gray:blob.dat blob.png
|
111
112
|
image.run(cmd)
|
112
113
|
# Update the image instance with the path of the properly formatted image, and return:
|
113
114
|
image.path = converted_image_path
|
@@ -186,10 +187,6 @@ module MiniMagick
|
|
186
187
|
@tempfile = tempfile # ensures that the tempfile will stick around until this image is garbage collected.
|
187
188
|
end
|
188
189
|
|
189
|
-
def escaped_path
|
190
|
-
Pathname.new(@path).to_s.inspect
|
191
|
-
end
|
192
|
-
|
193
190
|
# Checks to make sure that MiniMagick can read the file and understand it.
|
194
191
|
#
|
195
192
|
# This uses the 'identify' command line utility to check the file. If you are having
|
@@ -198,7 +195,7 @@ module MiniMagick
|
|
198
195
|
#
|
199
196
|
# @return [Boolean]
|
200
197
|
def valid?
|
201
|
-
run_command("identify",
|
198
|
+
run_command("identify", path)
|
202
199
|
true
|
203
200
|
rescue MiniMagick::Invalid
|
204
201
|
false
|
@@ -224,29 +221,29 @@ module MiniMagick
|
|
224
221
|
# Why do I go to the trouble of putting in newlines? Because otherwise animated gifs screw everything up
|
225
222
|
case value.to_s
|
226
223
|
when "colorspace"
|
227
|
-
run_command("identify", "-format",
|
224
|
+
run_command("identify", "-format", '%r\n', path).split("\n")[0].strip
|
228
225
|
when "format"
|
229
|
-
run_command("identify", "-format",
|
226
|
+
run_command("identify", "-format", '%m\n', path).split("\n")[0]
|
230
227
|
when "height"
|
231
|
-
run_command("identify", "-format",
|
228
|
+
run_command("identify", "-format", '%h\n', path).split("\n")[0].to_i
|
232
229
|
when "width"
|
233
|
-
run_command("identify", "-format",
|
230
|
+
run_command("identify", "-format", '%w\n', path).split("\n")[0].to_i
|
234
231
|
when "dimensions"
|
235
|
-
run_command("identify", "-format",
|
232
|
+
run_command("identify", "-format", '%w %h\n', path).split("\n")[0].split.map{|v|v.to_i}
|
236
233
|
when "size"
|
237
|
-
File.size(
|
234
|
+
File.size(path) # Do this because calling identify -format "%b" on an animated gif fails!
|
238
235
|
when "original_at"
|
239
236
|
# Get the EXIF original capture as a Time object
|
240
237
|
Time.local(*self["EXIF:DateTimeOriginal"].split(/:|\s+/)) rescue nil
|
241
238
|
when /^EXIF\:/i
|
242
|
-
result = run_command('identify', '-format', "
|
239
|
+
result = run_command('identify', '-format', "%[#{value}]", path).chop
|
243
240
|
if result.include?(",")
|
244
241
|
read_character_data(result)
|
245
242
|
else
|
246
243
|
result
|
247
244
|
end
|
248
245
|
else
|
249
|
-
run_command('identify', '-format',
|
246
|
+
run_command('identify', '-format', value, path).split("\n")[0]
|
250
247
|
end
|
251
248
|
end
|
252
249
|
|
@@ -256,7 +253,7 @@ module MiniMagick
|
|
256
253
|
#
|
257
254
|
# @return [String] Whatever the result from the command line is. May not be terribly useful.
|
258
255
|
def <<(*args)
|
259
|
-
run_command("mogrify", *args <<
|
256
|
+
run_command("mogrify", *args << path)
|
260
257
|
end
|
261
258
|
|
262
259
|
# This is used to change the format of the image. That is, from "tiff to jpg" or something like that.
|
@@ -282,17 +279,17 @@ module MiniMagick
|
|
282
279
|
c = CommandBuilder.new('mogrify', '-format', format)
|
283
280
|
yield c if block_given?
|
284
281
|
if page
|
285
|
-
c <<
|
282
|
+
c << "#{path}[#{page}]"
|
286
283
|
else
|
287
|
-
c <<
|
284
|
+
c << path
|
288
285
|
end
|
289
286
|
run(c)
|
290
287
|
|
291
|
-
old_path =
|
292
|
-
|
293
|
-
File.delete(old_path) if old_path !=
|
288
|
+
old_path = path
|
289
|
+
self.path = path.sub(/(\.\w*)?$/, ".#{format}")
|
290
|
+
File.delete(old_path) if old_path != path
|
294
291
|
|
295
|
-
unless File.exists?(
|
292
|
+
unless File.exists?(path)
|
296
293
|
raise MiniMagick::Error, "Unable to format to #{format}"
|
297
294
|
end
|
298
295
|
end
|
@@ -311,10 +308,10 @@ module MiniMagick
|
|
311
308
|
# Writes the temporary image that we are using for processing to the output path
|
312
309
|
def write(output_to)
|
313
310
|
if output_to.kind_of?(String) || !output_to.respond_to?(:write)
|
314
|
-
FileUtils.copy_file
|
315
|
-
run_command "identify", output_to.to_s
|
311
|
+
FileUtils.copy_file path, output_to
|
312
|
+
run_command "identify", output_to.to_s # Verify that we have a good image
|
316
313
|
else # stream
|
317
|
-
File.open(
|
314
|
+
File.open(path, "rb") do |f|
|
318
315
|
f.binmode
|
319
316
|
while chunk = f.read(8192)
|
320
317
|
output_to.write(chunk)
|
@@ -327,7 +324,7 @@ module MiniMagick
|
|
327
324
|
# Gives you raw image data back
|
328
325
|
# @return [String] binary string
|
329
326
|
def to_blob
|
330
|
-
f = File.new
|
327
|
+
f = File.new path
|
331
328
|
f.binmode
|
332
329
|
f.read
|
333
330
|
ensure
|
@@ -360,17 +357,12 @@ module MiniMagick
|
|
360
357
|
def combine_options(tool = "mogrify", &block)
|
361
358
|
c = CommandBuilder.new(tool)
|
362
359
|
|
363
|
-
c <<
|
360
|
+
c << path if tool.to_s == "convert"
|
364
361
|
block.call(c)
|
365
|
-
c <<
|
362
|
+
c << path
|
366
363
|
run(c)
|
367
364
|
end
|
368
365
|
|
369
|
-
# Check to see if we are running on win32 -- we need to escape things differently
|
370
|
-
def windows?
|
371
|
-
RUBY_PLATFORM =~ /mswin|mingw|cygwin/
|
372
|
-
end
|
373
|
-
|
374
366
|
def composite(other_image, output_extension = 'jpg', &block)
|
375
367
|
begin
|
376
368
|
second_tempfile = Tempfile.new(output_extension)
|
@@ -389,11 +381,6 @@ module MiniMagick
|
|
389
381
|
return Image.new(second_tempfile.path, second_tempfile)
|
390
382
|
end
|
391
383
|
|
392
|
-
# Outputs a carriage-return delimited format string for Unix and Windows
|
393
|
-
def format_option(format)
|
394
|
-
windows? ? "\"#{format}\\n\"" : "\"#{format}\\\\n\""
|
395
|
-
end
|
396
|
-
|
397
384
|
def run_command(command, *args)
|
398
385
|
# -ping "efficiently determine image characteristics."
|
399
386
|
if command == 'identify'
|
@@ -445,8 +432,6 @@ module MiniMagick
|
|
445
432
|
end
|
446
433
|
|
447
434
|
class CommandBuilder
|
448
|
-
attr_reader :args
|
449
|
-
|
450
435
|
def initialize(tool, *options)
|
451
436
|
@tool = tool
|
452
437
|
@args = []
|
@@ -454,7 +439,15 @@ module MiniMagick
|
|
454
439
|
end
|
455
440
|
|
456
441
|
def command
|
457
|
-
"#{
|
442
|
+
com = "#{@tool} #{args.join(' ')}".strip
|
443
|
+
com = "#{MiniMagick.processor} #{com}" unless MiniMagick.processor.nil?
|
444
|
+
|
445
|
+
com = File.join MiniMagick.processor_path, com unless MiniMagick.processor_path.nil?
|
446
|
+
com.strip
|
447
|
+
end
|
448
|
+
|
449
|
+
def args
|
450
|
+
@args.map(&:shellescape)
|
458
451
|
end
|
459
452
|
|
460
453
|
# Add each mogrify command in both underscore and dash format
|
@@ -493,7 +486,7 @@ module MiniMagick
|
|
493
486
|
push(@args.pop.gsub(/^-/, '+'))
|
494
487
|
if options.any?
|
495
488
|
options.each do |o|
|
496
|
-
push
|
489
|
+
push o
|
497
490
|
end
|
498
491
|
end
|
499
492
|
end
|
@@ -502,15 +495,11 @@ module MiniMagick
|
|
502
495
|
push "-#{command}"
|
503
496
|
if options.any?
|
504
497
|
options.each do |o|
|
505
|
-
push
|
498
|
+
push o
|
506
499
|
end
|
507
500
|
end
|
508
501
|
end
|
509
502
|
|
510
|
-
def escape_string(value)
|
511
|
-
Shellwords.escape(value.to_s)
|
512
|
-
end
|
513
|
-
|
514
503
|
def add_creation_operator(command, *options)
|
515
504
|
creation_command = command
|
516
505
|
if options.any?
|
data/lib/mini_magick/version.rb
CHANGED
@@ -3,6 +3,16 @@ require 'test_helper'
|
|
3
3
|
class CommandBuilderTest < Test::Unit::TestCase
|
4
4
|
include MiniMagick
|
5
5
|
|
6
|
+
def setup
|
7
|
+
@processor_path = MiniMagick.processor_path
|
8
|
+
@processor = MiniMagick.processor
|
9
|
+
end
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
MiniMagick.processor_path = @processor_path
|
13
|
+
MiniMagick.processor = @processor
|
14
|
+
end
|
15
|
+
|
6
16
|
def test_basic
|
7
17
|
c = CommandBuilder.new("test")
|
8
18
|
c.resize "30x40"
|
@@ -26,7 +36,7 @@ class CommandBuilderTest < Test::Unit::TestCase
|
|
26
36
|
def test_plus_modifier_and_multiple_options
|
27
37
|
c = CommandBuilder.new("test")
|
28
38
|
c.distort.+ 'srt', '0.6 20'
|
29
|
-
assert_equal '
|
39
|
+
assert_equal '\+distort srt 0.6\ 20', c.args.join(" ")
|
30
40
|
end
|
31
41
|
|
32
42
|
def test_valid_command
|
@@ -63,4 +73,18 @@ class CommandBuilderTest < Test::Unit::TestCase
|
|
63
73
|
assert_equal 'test -set colorspace\ RGB', c.command
|
64
74
|
end
|
65
75
|
|
76
|
+
def test_processor_path
|
77
|
+
MiniMagick.processor_path = "/a/strange/path"
|
78
|
+
c = CommandBuilder.new('test')
|
79
|
+
c.auto_orient
|
80
|
+
assert_equal c.command, "/a/strange/path/test -auto-orient"
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_processor_path_with_processor
|
84
|
+
MiniMagick.processor_path = "/a/strange/path"
|
85
|
+
MiniMagick.processor = "processor"
|
86
|
+
c = CommandBuilder.new('test')
|
87
|
+
c.auto_orient
|
88
|
+
assert_equal c.command, "/a/strange/path/processor test -auto-orient"
|
89
|
+
end
|
66
90
|
end
|
Binary file
|
data/test/image_test.rb
CHANGED
@@ -199,6 +199,16 @@ class ImageTest < Test::Unit::TestCase
|
|
199
199
|
image.destroy!
|
200
200
|
end
|
201
201
|
|
202
|
+
def test_image_combine_options_with_filename_with_special_characters_in_it
|
203
|
+
image = Image.new(SPECIAL_CHARS_IMAGE_PATH)
|
204
|
+
assert_nothing_raised do
|
205
|
+
image.combine_options("identify") do |c|
|
206
|
+
c.ping
|
207
|
+
end
|
208
|
+
end
|
209
|
+
image.destroy!
|
210
|
+
end
|
211
|
+
|
202
212
|
def test_exif
|
203
213
|
image = Image.open(EXIF_IMAGE_PATH)
|
204
214
|
assert_equal('0220', image["exif:ExifVersion"])
|
@@ -236,6 +246,23 @@ class ImageTest < Test::Unit::TestCase
|
|
236
246
|
image.destroy!
|
237
247
|
end
|
238
248
|
|
249
|
+
def test_change_format_of_image_with_special_characters
|
250
|
+
tempfile = Tempfile.new('magick with special! "chars\'')
|
251
|
+
|
252
|
+
File.open(SIMPLE_IMAGE_PATH, 'rb') do |f|
|
253
|
+
tempfile.write(f.read)
|
254
|
+
tempfile.rewind
|
255
|
+
end
|
256
|
+
|
257
|
+
image = Image.new(tempfile.path)
|
258
|
+
image.format('png')
|
259
|
+
assert File.exists?(image.path)
|
260
|
+
image.destroy!
|
261
|
+
|
262
|
+
File.delete(image.path)
|
263
|
+
tempfile.unlink
|
264
|
+
end
|
265
|
+
|
239
266
|
def test_bad_method_bug
|
240
267
|
image = Image.open(TIFF_IMAGE_PATH)
|
241
268
|
begin
|
data/test/test_helper.rb
CHANGED
@@ -7,15 +7,16 @@ require File.expand_path('../../lib/mini_magick', __FILE__)
|
|
7
7
|
|
8
8
|
module MiniMagickTestFiles
|
9
9
|
test_files = File.expand_path(File.dirname(__FILE__) + "/files")
|
10
|
-
SIMPLE_IMAGE_PATH
|
11
|
-
MINUS_IMAGE_PATH
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
10
|
+
SIMPLE_IMAGE_PATH = test_files + "/simple.gif"
|
11
|
+
MINUS_IMAGE_PATH = test_files + "/simple-minus.gif"
|
12
|
+
SPECIAL_CHARS_IMAGE_PATH = test_files + "/special! \"chars'.gif"
|
13
|
+
TIFF_IMAGE_PATH = test_files + "/leaves (spaced).tiff"
|
14
|
+
NOT_AN_IMAGE_PATH = test_files + "/not_an_image.php"
|
15
|
+
GIF_WITH_JPG_EXT = test_files + "/actually_a_gif.jpg"
|
16
|
+
EXIF_IMAGE_PATH = test_files + "/trogdor.jpg"
|
17
|
+
CAP_EXT_PATH = test_files + "/trogdor_capitalized.JPG"
|
18
|
+
ANIMATION_PATH = test_files + "/animation.gif"
|
19
|
+
PNG_PATH = test_files + "/png.png"
|
20
|
+
COMP_IMAGE_PATH = test_files + "/composited.jpg"
|
21
|
+
ERRONEOUS_IMAGE_PATH = test_files + "/erroneous.jpg"
|
21
22
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mini_magick
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-
|
14
|
+
date: 2013-05-21 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: subexec
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- test/files/png.png
|
86
86
|
- test/files/simple-minus.gif
|
87
87
|
- test/files/simple.gif
|
88
|
+
- test/files/special! "chars'.gif
|
88
89
|
- test/files/trogdor.jpg
|
89
90
|
- test/files/trogdor_capitalized.JPG
|
90
91
|
- test/image_test.rb
|
@@ -109,7 +110,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
110
|
- - ! '>='
|
110
111
|
- !ruby/object:Gem::Version
|
111
112
|
version: '0'
|
112
|
-
requirements:
|
113
|
+
requirements:
|
114
|
+
- You must have ImageMagick or GraphicsMagick installed
|
113
115
|
rubyforge_project:
|
114
116
|
rubygems_version: 1.8.23
|
115
117
|
signing_key:
|
@@ -126,9 +128,11 @@ test_files:
|
|
126
128
|
- test/files/png.png
|
127
129
|
- test/files/simple-minus.gif
|
128
130
|
- test/files/simple.gif
|
131
|
+
- test/files/special! "chars'.gif
|
129
132
|
- test/files/trogdor.jpg
|
130
133
|
- test/files/trogdor_capitalized.JPG
|
131
134
|
- test/image_test.rb
|
132
135
|
- test/leaves (spaced).tiff
|
133
136
|
- test/test_helper.rb
|
134
137
|
- test/trogdor_capitalized.JPG
|
138
|
+
has_rdoc:
|