mini_magick 3.0 → 3.2

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.0
1
+ 3.2
data/lib/mini_magick.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'tempfile'
2
2
  require 'subexec'
3
+ require 'pathname'
3
4
 
4
5
  module MiniMagick
5
6
  class << self
@@ -129,7 +130,10 @@ module MiniMagick
129
130
  @path = input_path
130
131
  @tempfile = tempfile # ensures that the tempfile will stick around until this image is garbage collected.
131
132
  end
132
-
133
+
134
+ def escaped_path
135
+ Pathname.new(@path).to_s.gsub(" ", "\\ ")
136
+ end
133
137
 
134
138
  # Checks to make sure that MiniMagick can read the file and understand it.
135
139
  #
@@ -152,6 +156,7 @@ module MiniMagick
152
156
  # image["format"] #=> "TIFF"
153
157
  # image["height"] #=> 41 (pixels)
154
158
  # image["width"] #=> 50 (pixels)
159
+ # image["colorspace"] #=> "DirectClassRGB"
155
160
  # image["dimensions"] #=> [50, 41]
156
161
  # image["size"] #=> 2050 (bits)
157
162
  # image["original_at"] #=> 2005-02-23 23:17:24 +0000 (Read from Exif data)
@@ -163,28 +168,30 @@ module MiniMagick
163
168
  def [](value)
164
169
  # Why do I go to the trouble of putting in newlines? Because otherwise animated gifs screw everything up
165
170
  case value.to_s
171
+ when "colorspace"
172
+ run_command("identify", "-format", format_option("%r"), escaped_path).split("\n")[0]
166
173
  when "format"
167
- run_command("identify", "-format", format_option("%m"), @path).split("\n")[0]
174
+ run_command("identify", "-format", format_option("%m"), escaped_path).split("\n")[0]
168
175
  when "height"
169
- run_command("identify", "-format", format_option("%h"), @path).split("\n")[0].to_i
176
+ run_command("identify", "-format", format_option("%h"), escaped_path).split("\n")[0].to_i
170
177
  when "width"
171
- run_command("identify", "-format", format_option("%w"), @path).split("\n")[0].to_i
178
+ run_command("identify", "-format", format_option("%w"), escaped_path).split("\n")[0].to_i
172
179
  when "dimensions"
173
- run_command("identify", "-format", format_option("%w %h"), @path).split("\n")[0].split.map{|v|v.to_i}
180
+ run_command("identify", "-format", format_option("%w %h"), escaped_path).split("\n")[0].split.map{|v|v.to_i}
174
181
  when "size"
175
182
  File.size(@path) # Do this because calling identify -format "%b" on an animated gif fails!
176
183
  when "original_at"
177
184
  # Get the EXIF original capture as a Time object
178
185
  Time.local(*self["EXIF:DateTimeOriginal"].split(/:|\s+/)) rescue nil
179
186
  when /^EXIF\:/i
180
- result = run_command('identify', '-format', "\"%[#{value}]\"", @path).chop
187
+ result = run_command('identify', '-format', "\"%[#{value}]\"", escaped_path).chop
181
188
  if result.include?(",")
182
189
  read_character_data(result)
183
190
  else
184
191
  result
185
192
  end
186
193
  else
187
- run_command('identify', '-format', "\"#{value}\"", @path).split("\n")[0]
194
+ run_command('identify', '-format', "\"#{value}\"", escaped_path).split("\n")[0]
188
195
  end
189
196
  end
190
197
 
@@ -194,7 +201,7 @@ module MiniMagick
194
201
  #
195
202
  # @return [String] Whatever the result from the command line is. May not be terribly useful.
196
203
  def <<(*args)
197
- run_command("mogrify", *args << @path)
204
+ run_command("mogrify", *args << escaped_path)
198
205
  end
199
206
 
200
207
  # This is used to change the format of the image. That is, from "tiff to jpg" or something like that.
@@ -212,7 +219,10 @@ module MiniMagick
212
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.
213
220
  # @return [nil]
214
221
  def format(format, page = 0)
215
- 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)
216
226
 
217
227
  old_path = @path.dup
218
228
  @path.sub!(/(\.\w*)?$/, ".#{format}")
@@ -246,7 +256,9 @@ module MiniMagick
246
256
  def write(output_to)
247
257
  if output_to.kind_of?(String) || !output_to.respond_to?(:write)
248
258
  FileUtils.copy_file @path, output_to
249
- 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
250
262
  else # stream
251
263
  File.open(@path, "rb") do |f|
252
264
  f.binmode
@@ -322,6 +334,11 @@ module MiniMagick
322
334
  end
323
335
 
324
336
  def run_command(command, *args)
337
+ # -ping "efficiently determine image characteristics."
338
+ if command == 'identify'
339
+ args.unshift '-ping'
340
+ end
341
+
325
342
  run(CommandBuilder.new(command, *args))
326
343
  end
327
344
 
@@ -385,15 +402,27 @@ module MiniMagick
385
402
  raise Error, "You must call 'format' on the image object directly!"
386
403
  elsif MOGRIFY_COMMANDS.include?(guessed_command_name)
387
404
  add(guessed_command_name, *options)
405
+ self
388
406
  else
389
407
  super(symbol, *args)
390
408
  end
391
409
  end
392
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
+
393
420
  def add(command, *options)
394
421
  push "-#{command}"
395
422
  if options.any?
396
- push "\"#{options.join(" ")}\""
423
+ options.each do |o|
424
+ push "\"#{ o }\""
425
+ end
397
426
  end
398
427
  end
399
428
 
@@ -401,11 +430,5 @@ module MiniMagick
401
430
  @args << arg.to_s.strip
402
431
  end
403
432
  alias :<< :push
404
-
405
- # @deprecated Please don't use the + method its has been deprecated
406
- def +(value)
407
- warn "Warning: The MiniMagick::ComandBuilder#+ command has been deprecated. Please use c << '+#{value}' instead"
408
- push "+#{value}"
409
- end
410
433
  end
411
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
data/test/image_test.rb CHANGED
@@ -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__)
@@ -14,7 +13,7 @@ class ImageTest < Test::Unit::TestCase
14
13
 
15
14
  SIMPLE_IMAGE_PATH = CURRENT_DIR + "simple.gif"
16
15
  MINUS_IMAGE_PATH = CURRENT_DIR + "simple-minus.gif"
17
- TIFF_IMAGE_PATH = CURRENT_DIR + "leaves.tiff"
16
+ TIFF_IMAGE_PATH = CURRENT_DIR + "leaves spaced.tiff"
18
17
  NOT_AN_IMAGE_PATH = CURRENT_DIR + "not_an_image.php"
19
18
  GIF_WITH_JPG_EXT = CURRENT_DIR + "actually_a_gif.jpg"
20
19
  EXIF_IMAGE_PATH = CURRENT_DIR + "trogdor.jpg"
@@ -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
- - 0
8
- version: "3.0"
8
+ - 2
9
+ version: "3.2"
9
10
  platform: ruby
10
11
  authors:
11
12
  - Corey Johnson
@@ -15,16 +16,18 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2010-10-28 00:00:00 +01:00
19
+ date: 2011-01-11 00:00:00 +00:00
19
20
  default_executable:
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
22
23
  name: subexec
23
24
  prerelease: false
24
25
  requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
25
27
  requirements:
26
28
  - - ~>
27
29
  - !ruby/object:Gem::Version
30
+ hash: 23
28
31
  segments:
29
32
  - 0
30
33
  - 0
@@ -32,20 +35,6 @@ dependencies:
32
35
  version: 0.0.4
33
36
  type: :runtime
34
37
  version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: mocha
37
- prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
39
- requirements:
40
- - - ~>
41
- - !ruby/object:Gem::Version
42
- segments:
43
- - 0
44
- - 9
45
- - 9
46
- version: 0.9.9
47
- type: :development
48
- version_requirements: *id002
49
38
  description: ""
50
39
  email:
51
40
  - probablycorey@gmail.com
@@ -64,6 +53,16 @@ files:
64
53
  - Rakefile
65
54
  - lib/mini_gmagick.rb
66
55
  - lib/mini_magick.rb
56
+ - test/actually_a_gif.jpg
57
+ - test/animation.gif
58
+ - test/command_builder_test.rb
59
+ - test/composited.jpg
60
+ - test/image_test.rb
61
+ - test/leaves spaced.tiff
62
+ - test/not_an_image.php
63
+ - test/simple-minus.gif
64
+ - test/simple.gif
65
+ - test/trogdor.jpg
67
66
  has_rdoc: true
68
67
  homepage: http://github.com/probablycorey/mini_magick
69
68
  licenses: []
@@ -74,23 +73,27 @@ rdoc_options: []
74
73
  require_paths:
75
74
  - lib
76
75
  required_ruby_version: !ruby/object:Gem::Requirement
76
+ none: false
77
77
  requirements:
78
78
  - - ">="
79
79
  - !ruby/object:Gem::Version
80
+ hash: 3
80
81
  segments:
81
82
  - 0
82
83
  version: "0"
83
84
  required_rubygems_version: !ruby/object:Gem::Requirement
85
+ none: false
84
86
  requirements:
85
87
  - - ">="
86
88
  - !ruby/object:Gem::Version
89
+ hash: 3
87
90
  segments:
88
91
  - 0
89
92
  version: "0"
90
93
  requirements: []
91
94
 
92
95
  rubyforge_project:
93
- rubygems_version: 1.3.6
96
+ rubygems_version: 1.3.7
94
97
  signing_key:
95
98
  specification_version: 3
96
99
  summary: Manipulate images with minimal use of memory via ImageMagick / GraphicsMagick
@@ -100,7 +103,7 @@ test_files:
100
103
  - test/command_builder_test.rb
101
104
  - test/composited.jpg
102
105
  - test/image_test.rb
103
- - test/leaves.tiff
106
+ - test/leaves spaced.tiff
104
107
  - test/not_an_image.php
105
108
  - test/simple-minus.gif
106
109
  - test/simple.gif
File without changes