mini_magick 3.1 → 3.2

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/VERSION CHANGED
@@ -1 +1 @@
1
- 3.1
1
+ 3.2
@@ -156,6 +156,7 @@ module MiniMagick
156
156
  # image["format"] #=> "TIFF"
157
157
  # image["height"] #=> 41 (pixels)
158
158
  # image["width"] #=> 50 (pixels)
159
+ # image["colorspace"] #=> "DirectClassRGB"
159
160
  # image["dimensions"] #=> [50, 41]
160
161
  # image["size"] #=> 2050 (bits)
161
162
  # image["original_at"] #=> 2005-02-23 23:17:24 +0000 (Read from Exif data)
@@ -167,6 +168,8 @@ module MiniMagick
167
168
  def [](value)
168
169
  # Why do I go to the trouble of putting in newlines? Because otherwise animated gifs screw everything up
169
170
  case value.to_s
171
+ when "colorspace"
172
+ run_command("identify", "-format", format_option("%r"), escaped_path).split("\n")[0]
170
173
  when "format"
171
174
  run_command("identify", "-format", format_option("%m"), escaped_path).split("\n")[0]
172
175
  when "height"
@@ -216,7 +219,10 @@ module MiniMagick
216
219
  # @param page [Integer] If this is an animated gif, say which 'page' you want with an integer. Leave as default if you don't care.
217
220
  # @return [nil]
218
221
  def format(format, page = 0)
219
- run_command("mogrify", "-format", format, @path)
222
+ c = CommandBuilder.new('mogrify', '-format', format)
223
+ yield c if block_given?
224
+ c << @path
225
+ run(c)
220
226
 
221
227
  old_path = @path.dup
222
228
  @path.sub!(/(\.\w*)?$/, ".#{format}")
@@ -250,7 +256,9 @@ module MiniMagick
250
256
  def write(output_to)
251
257
  if output_to.kind_of?(String) || !output_to.respond_to?(:write)
252
258
  FileUtils.copy_file @path, output_to
253
- run_command "identify", output_to # Verify that we have a good image
259
+ # We need to escape the output path if it contains a space
260
+ escaped_output_to = output_to.to_s.gsub(' ', '\\ ')
261
+ run_command "identify", escaped_output_to # Verify that we have a good image
254
262
  else # stream
255
263
  File.open(@path, "rb") do |f|
256
264
  f.binmode
@@ -326,6 +334,11 @@ module MiniMagick
326
334
  end
327
335
 
328
336
  def run_command(command, *args)
337
+ # -ping "efficiently determine image characteristics."
338
+ if command == 'identify'
339
+ args.unshift '-ping'
340
+ end
341
+
329
342
  run(CommandBuilder.new(command, *args))
330
343
  end
331
344
 
@@ -389,15 +402,27 @@ module MiniMagick
389
402
  raise Error, "You must call 'format' on the image object directly!"
390
403
  elsif MOGRIFY_COMMANDS.include?(guessed_command_name)
391
404
  add(guessed_command_name, *options)
405
+ self
392
406
  else
393
407
  super(symbol, *args)
394
408
  end
395
409
  end
396
410
 
411
+ def +(*options)
412
+ push(@args.pop.gsub /^-/, '+')
413
+ if options.any?
414
+ options.each do |o|
415
+ push "\"#{ o }\""
416
+ end
417
+ end
418
+ end
419
+
397
420
  def add(command, *options)
398
421
  push "-#{command}"
399
422
  if options.any?
400
- push "\"#{options.join(" ")}\""
423
+ options.each do |o|
424
+ push "\"#{ o }\""
425
+ end
401
426
  end
402
427
  end
403
428
 
@@ -405,11 +430,5 @@ module MiniMagick
405
430
  @args << arg.to_s.strip
406
431
  end
407
432
  alias :<< :push
408
-
409
- # @deprecated Please don't use the + method its has been deprecated
410
- def +(value)
411
- warn "Warning: The MiniMagick::ComandBuilder#+ command has been deprecated. Please use c << '+#{value}' instead"
412
- push "+#{value}"
413
- end
414
433
  end
415
434
  end
@@ -14,10 +14,16 @@ class CommandBuilderTest < Test::Unit::TestCase
14
14
  def test_complicated
15
15
  c = CommandBuilder.new("test")
16
16
  c.resize "30x40"
17
- c.alpha 1, 3, 4
17
+ c.alpha "1 3 4"
18
18
  c.resize "mome fingo"
19
19
  assert_equal "-resize \"30x40\" -alpha \"1 3 4\" -resize \"mome fingo\"", c.args.join(" ")
20
20
  end
21
+
22
+ def test_plus_modifier_and_multiple_options
23
+ c = CommandBuilder.new("test")
24
+ c.distort.+ 'srt', '0.6 20'
25
+ assert_equal "+distort \"srt\" \"0.6 20\"", c.args.join(" ")
26
+ end
21
27
 
22
28
  def test_valid_command
23
29
  begin
@@ -1,6 +1,5 @@
1
1
  require 'rubygems'
2
2
  require 'test/unit'
3
- require 'mocha'
4
3
  require 'pathname'
5
4
  require 'stringio'
6
5
  require File.expand_path('../../lib/mini_magick', __FILE__)
@@ -71,6 +70,19 @@ class ImageTest < Test::Unit::TestCase
71
70
  image.destroy!
72
71
  end
73
72
 
73
+ def test_image_write_with_space_in_output_path
74
+ output_path = "test output.gif"
75
+ begin
76
+ image = Image.new(SIMPLE_IMAGE_PATH)
77
+ image.write output_path
78
+
79
+ assert File.exists?(output_path)
80
+ ensure
81
+ File.delete output_path
82
+ end
83
+ image.destroy!
84
+ end
85
+
74
86
  def test_image_write_with_stream
75
87
  stream = StringIO.new
76
88
  image = Image.open(SIMPLE_IMAGE_PATH)
@@ -98,6 +110,7 @@ class ImageTest < Test::Unit::TestCase
98
110
  assert_equal 150, image[:width]
99
111
  assert_equal 55, image[:height]
100
112
  assert_equal [150, 55], image[:dimensions]
113
+ assert_equal 'PseudoClassRGB', image[:colorspace]
101
114
  assert_match(/^gif$/i, image[:format])
102
115
  image.destroy!
103
116
  end
@@ -249,16 +262,4 @@ class ImageTest < Test::Unit::TestCase
249
262
  end
250
263
  image.destroy!
251
264
  end
252
-
253
- # testing that if copying files formatted from an animation fails,
254
- # it raises an appropriate error
255
- def test_throw_animation_copy_after_format_error
256
- image = Image.open(ANIMATION_PATH)
257
- FileUtils.stubs(:copy_file).raises(Errno::ENOENT)
258
- assert_raises MiniMagick::Error do
259
- image.format('png')
260
- end
261
- end
262
-
263
-
264
265
  end
metadata CHANGED
@@ -1,11 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mini_magick
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 3
4
5
  prerelease: false
5
6
  segments:
6
7
  - 3
7
- - 1
8
- version: "3.1"
8
+ - 2
9
+ version: "3.2"
9
10
  platform: ruby
10
11
  authors:
11
12
  - Corey Johnson
@@ -15,7 +16,7 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2010-11-09 00:00:00 +00:00
19
+ date: 2011-01-11 00:00:00 +00:00
19
20
  default_executable:
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
@@ -26,6 +27,7 @@ dependencies:
26
27
  requirements:
27
28
  - - ~>
28
29
  - !ruby/object:Gem::Version
30
+ hash: 23
29
31
  segments:
30
32
  - 0
31
33
  - 0
@@ -33,21 +35,6 @@ dependencies:
33
35
  version: 0.0.4
34
36
  type: :runtime
35
37
  version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: mocha
38
- prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
42
- - - ~>
43
- - !ruby/object:Gem::Version
44
- segments:
45
- - 0
46
- - 9
47
- - 9
48
- version: 0.9.9
49
- type: :development
50
- version_requirements: *id002
51
38
  description: ""
52
39
  email:
53
40
  - probablycorey@gmail.com
@@ -90,6 +77,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
90
77
  requirements:
91
78
  - - ">="
92
79
  - !ruby/object:Gem::Version
80
+ hash: 3
93
81
  segments:
94
82
  - 0
95
83
  version: "0"
@@ -98,6 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
86
  requirements:
99
87
  - - ">="
100
88
  - !ruby/object:Gem::Version
89
+ hash: 3
101
90
  segments:
102
91
  - 0
103
92
  version: "0"